Dynamic Variables - Usage Examples

pako

New member
Hi,

I've read the documentation on Dynamic Variables, but can't yet figure out how to use them properly.

Clicking the small white circle in the Inspector of a shared variable in a custom Action task, selecting "Dynamic", and then and entering a name was fine. However, after setting the value of this variable from inside OnAwake() of this custom task, I can't use the set variable in a sibling task by using the same dynamic variable name.

Here's the code of the custom Task, where I declare the SharedFloat TestVariable, which I want to use as the the WaitTime in a Wait task.

1047


Here's the BT with the DynamicVariableTest task, and the TestVariable set as a Dynamic variable named "DynamicVar".

1048


When I try to set the Wait tasks's WaitTime field to the "DynamicVar" Dynamic variable which was already created, this variable isn't shown in the drop down. So. I thought of selecting "Dynamic" and then entering the same name "DynamicVar". However, it doesn't work, and WaitTime ends up with a value of 0.

1049


I'd really appreciate if you tell me what I'm doing wrong, and possibly point me to any existing examples, or give me some step-by-step instructions on how to test the usage of dynamic variables, for learning purposes.

Thank you. DynamicVariableTest Code.pngDynamic Variable Created.pngTrying to use the Created Dynamic Variable.png
 
By setting:

Code:
TestVariable = 10f;

You are actually creating a new variable instance so that's why things are no longer hooked up. You'll instead want to set the value of the variable:

Code:
TestVariable.Value = 10f;
 
By setting:

Code:
TestVariable = 10f;

You are actually creating a new variable instance so that's why things are no longer hooked up. You'll instead want to set the value of the variable:

Code:
TestVariable.Value = 10f;

So simple, I don't know how I could miss this!

Thanks Justin!
 
Hi! I just found this thread because I was having the exact same issue. However, now that I'm setting the variable by using .Value, it's still 0,0,0 in the second node instead of the value it should be.

1616534442749.png

Those are both the same dynamic variable:
1616534472286.png
1616534481280.png
 
Hi! Yes, this is exactly how I'm doing it (I wasn't at first, but then I read that post and changed it). Here's my full code for RunEnvironmentQuery:

C#:
using UnityEngine;
using BehaviorDesigner.Runtime;
using BehaviorDesigner.Runtime.Tasks;

public class RunEnvironmentQuery : Action
{
    public SharedEnvQuery envQueryRef;
    public SharedTargetPicker targetPickerRef;
    public EQSParams envQueryParams;
    public SharedVector3 pointPicked;

    public override TaskStatus OnUpdate()
    {
        if (targetPickerRef.Value && targetPickerRef.Value.currentTarget)
        {
            AIGridPoint aiGridPoint = envQueryRef.Value.RunQuery(targetPickerRef.Value.currentTarget.transform.position, envQueryParams);
            pointPicked.Value = aiGridPoint.position;
            return TaskStatus.Success;
        }
        else
        {
            return TaskStatus.Failure;
        }
    }
}
 
That looks correct. Just to make sure you have the right setup if you use a regular SharedVariable can you get it working?
 
Sorry – I don't think I understand. What do you mean by "regular SharedVariable?" Something that isn't SharedVector3?
 
I was creating a sample scene to attach a working version but I am noticing a similar problem as you. I'll get it fixed and send you the updated version.

Edit: Dynamic variables work correctly when you do not have the behavior tree selected. I've fixed it in the case where it is selected though.
 

Attachments

  • DynamicVariable.unity
    9.7 KB · Views: 10
I've found the culprit on my end: The issue reappears when Enter Play Mode Options are enabled in Project Settings > Editor, and Reload Domain is left unchecked.
I take from it that Behavior Designer does not support Enter Play Mode Settings. If so, is such support planned - or maybe, it's possible to reset BD so that it does work with it?
 
Top