The variables of prefab instance is reverted when running the scene

titidatiti

New member
I'm using Behavior Designer in Unity.

I have an NPC prefab with a behavior tree and I use this prefab to create all the NPCs in the scene.
To make the NPCs look different, I have several bool variables, such as: IsSleeping, WithHat, WithBackpacks and so on.

However, when I click the run button, all the variables are reverted to the same as the prefab is.
Is is possible to set the variables for instances of a prefab?

Thank you!
 
For this situation I recommend using external trees. You are able to set the variables on the prefab instance and then have them override the value.
 
For this situation I recommend using external trees. You are able to set the variables on the prefab instance and then have them override the value.
Thank you for reply.

I tried to use external trees, but external trees bring a new problem. It's quite hard to reference variables in an external tree to the variables in the gameObject's MonoBehaviour.

Now I'm solving the problem by creating a script. The script calls SetVariableValue in the script on Awake to set the variables in the behavior tree.

It seems to work now, but I wonder if the solusion will cause other problems?
 
You can create a local variable on each behavior tree instance and then reference that value within your own script. But also setting the variable value on awake should work well.
 
Top