Receiving sent values from instanced versions of the same Pd patch.
See original GitHub issueHi! I’m loving this project as it’s exactly what my project requires to get the audio-end working flexibly!
I’m running into an issue where I need to receive a float value from the patch. After following the LibPd-2-Unity tutorial, I have the following code receiving a float value “volume” from the patch and influencing the scale of the object.
public void FloatReceive(string sender, float value)
{
if(sender == "volume")
{
scaleObject.localScale = new Vector3(0.1f+(value/1f), 0.1f+(value/1f), 0.1f+(value/1f));
}
}
However, I have two game objects, each with their own LibPdInstance running this single patch, and both are receiving the volume value from the first instance of the patch.
Is this an issue with the way my variables are setup? See this video for a short demo of the issue: https://www.youtube.com/watch?v=c_jD0dD6zRg
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Multiple send~ instances - PURE DATA forum
i know that multipe instances of the same send~ cause an error, but i have eight of them and they all seem to...
Read more >local send/receive (within the same patch only) - MaxMSP ...
Your original question may have been about subpatches, which aren't abstractions, they're part of the main patch. So the #0 won't work in...
Read more >Meet the Cat: A Quick Introduction to Purr Data
Pd requires that patches are loaded in the same program instance if they are to communicate via Pd's built-in messaging system (send/receive), ...
Read more >Python Mock object with method called multiple times
I have a class that I'm testing which has as a dependency another class (an instance of which gets passed to the CUT's...
Read more >Using Pure Data
The relationship is one to many, so only one send can have a particular name but can be picked up by multiple receive...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Redescription of desired effect
I can achieve 2 and 3 with a bit of learning so this issue is mainly about 5.
Solution
I just stumbled across this solution, came back to this issue and found that its essentially what you pointed me in the direction of! It involves sending the name of the GameObject (which will eventually iterate as they spawn (e.g. object-0, object-1, object-2) over to PureData to act as a kind of psudeo
$0that Unity can access (because it put it there).This looks quite similar to the quick fix I did above, but whereas that fix still required a unique script per GameObject, this fix uses the same script and Pure Data patch per GameObject.
In Pure Data
Set up a receive mechanism that stores the GameObject’s name and accordingly sets the name of a send object inthe patch
In Unity/C#
pdPatchis a variable containing your LibPdInstance) i. Send the name of the GameObject over to the receive object you made above.pdPatch.SendSymbol("label",gameObject.name);ii. Bind to the name of the GameObjectpdPatch.Bind(gameObject.name);iii. Set up a conditional BangRecieve() function so that the you can make stuff happen only if the bang comes from the patch who’s index is equal to your object’s name (if you dont do this, you will receive multiple bangs, although unique they will be copied for everypublic void BangReceive()):Next steps
I will want to bind to more than just one outgoing message from PureData. I will try doing this by binding to indexed parameters that still use the GameObject’s name:
pdPatch.Bind(gameObject.name+"volume")and set up multiple send objects as the above screenshot shows by using[list append]then[list trim]so that PureData sends out via an object named[sphere-id-1volume]for example.Eventually I’ll tackle building the GameObject naming into a prefab instancer, but the way I see it, this is probably the best fix I can go with for the time being
Caveat
A downside is having to set up the new send system with a testing mechanism (since without Unity telling it what the send object is sending to, it doesnt go anywhere). You can see I did this by sending
[sphere-id-0(to make sure that the mechanism works.Thank you so much for your reply. I will have an investigate over the next couple weeks and report back here if thats okay? Could be useful for future repo users.