NodeCanvas Forums › Support › Problem with getting and saving variables from other agents
I’ve been trying to get an int from a TriggerEnter object, and save it to a variable of the object that was triggered. I have used agent override, but that saves the variable to itself (the triggerenter object becomes the agent, which saves its own team to its own _triggerEnterTeam variable, not to the behaviour tree owner). I’ve also been trying to use Iterate, but I think I am maybe confusing that somehow. It is sort of like agent override, but for each item being iterated over, right? That leads to the same problem. I’ve also used “get other blackboard variable” but that ALSO doesn’t work the way I thought it would. My last try was to just do that through code, and call the script in my behaviour tree, but using GetComponent<Blackboard>().GetVariable<“Team”>(); returns a string, and I need an int. I tried some of the others (getvariablebyID, geValue, etc) but they didn’t work either.
I guess this is mostly a question about how to save a variable from an object entering my trigger. And tangentially the similarities and differences between iterate and agent override (other than the actual iteration, which is obviously different).
Just as an aside, I really like nodeCanvas, and I think it will really help me. Thanks for making such a great product.
(The attached image is just to give an idea of what I’m going for).
Hello and thanks for your feedback. I am glad you like NodeCanvas.
AgentOverride decorator, will simply change the “target object” which will execute the rest of the tasks in the nodes bellow that decorator. It is exactly the same as manually going into each of those task bellow, and -by checking the checkbox- override the agent so that it’s not using “Self”, but rather some other agent provided, through a variable or a direct assignment.
Iterator is really different that AgentOverride and does not have any immediate relation. The Iterator decorator, will iterate a list for each of each elements, and for each of those elements, A) save that element in a variable and B) execute the decorated node.
Regarding setting a variable of another agent, the “Set Other Variable” tasks is indeed what you should be using if you want to do it visually (no coding). Just make sure to select the correct type of the variable you want to set with the relevant button found within the inspector of that task, as well as set the target Blackboard of which you want to set the variable to, by “overriding the target agent”.
As you see above, I have override the target (by checking the checkbox) so that it’s not using “Self”, but rather a spececific Blackboard reference that I’ve assigned. In this case, the Blackboard of “GameObject2” (just drag and drop the gameobject). You could of course also use a variable instead of direct assignment if so desired.
Then for the variable name I want to set, I used “TargetVariableName”, while for it’s new value, I linked a GameObject variable type named “TriggerTarget”.
The “TriggerTarget” variable, was previously set by the CheckTrigger condition task:
And this is the BT as an example:
As far as setting a blackboard variable from code, it can be done with using Blackboard.GetValue
and Blackboard.SetValue
methods, as I explained in your other post [HERE] 🙂
Let me know if the above help, or if you still encounter any troubles.
Thanks again!
Join us on Discord: https://discord.gg/97q2Rjh
Hey, I don’t know what happened. Seems like half our thread went missing. Did you see my last post?
I am still getting a failure return on trying to save the other variable. I’m not really sure what’s happening, so any tips or direction would be helpful.
Hello,
There indeed was a ridiculous forums failure wiping some posts, which I investigate into right now.
Judging from your screenshot, it clearly looks like that the gameobject you have assigned as “_currentPossibleTarget”, does NOT have a Blackboard component attached, hence why the (Blackboard) text is in red.
Your should also get a relevant error in the log like (“Failed to resolve Agent to requested type Blackboard….”).
Are you certain that the “_currentPossibleTarget” variable is not null and does indeed have a Blackboard component attached at the time the action is executed?
Thanks.
Join us on Discord: https://discord.gg/97q2Rjh
I am thinking that it _currentPossibleTarget is returning null somehow, but I’m not sure. Both _currentPossibleTarget and _targetCheckList contain the “Creep2.Revision1” gameobject in them, and that gameobject has the blackboard as attached, which you can see in the screenshots. I’m not getting any relevant errors either.
Thanks for all the help.
Actually, on a hunch, inside the “Get Other Blackboard Variable” action, I changed the target variable name from searching for the Team variable (which I selected from the dropdown), to searching using the string “Team”.
Now it works
Thanks for the follow up.
Glad to know you got it solved.
I have made similar mistakes myself in the past 🙂
Join us on Discord: https://discord.gg/97q2Rjh