Is it possible to limit the value of a local variable of a Behaviour Tree?

Pietrofonix

New member
Hi guys, I have a question about the value of local variables of a behaviour tree. Basically in a MonoBehaviour script to limit the value of a public or serialized variable you need to put the Range attribute before it.
Example:

[Range(1, 5)]
public int x;

Is it possible to do it for the local variables we add in a behaviour tree? It would be really helpful for the designers that need to adjust the parameters in the Inspector
 
Last edited:

Justin

Administrator
Staff member
There is a range attribute for Behavior Designer as well. Furthermore, you can create your own object drawer to limit any variable type:

 

Pietrofonix

New member
Thank you for the answer. I tried the Range attribute, but it only works with the normal variables, not the Shared ones. Doing so the inspector only change inside the node of the behaviour tree but I don't want this. It would be better if the designers could modify the parameters directly within the BehaviorTree component. The problem is that if I want to limit a Shared variable I must create a CustomClass with a variable and then set the limit of that variable inside the CustomClassDrawer script. I would like to keep the generic SharedFloat class and then put the Range attribute on it with min and max unique for each SharedFloat variable
 

Justin

Administrator
Staff member
I'm not completely following - so you want a SharedFloat, but have that SharedFloat always require a range? Using an attribute above the field is generally the best way to approach this for the most flexibility. That does mean that you would need to add the attribute for each task but that's probably what you want anyway so every single SharedFloat doesn't have the limit.
 

Pietrofonix

New member
No, I want to use the range attribute freely with all shared variables, but it doesn't work. Example:

[Range(1, 10)]
public SharedFloat myFloat;

Doing so the inspector of the node is empty, it doesn't show anything. If I remove the range attribute I can see the variable. I'd like to assign the shared variable with the range attribute to the local variable of the BehaviourTree and see the limit directly inside the component
 

Justin

Administrator
Staff member
That makes more sense. The range attribute works on floats but I'll add it to my list to support SharedFloats. It'll take a new object drawer really similar to the existing object drawer. You can use that as an example of you want to add it sooner.
 
Top