Behavior Tree within a Prefab does not update correctly when the behavior tree in the prefab asset is changed

slipyfrog

New member
Hope you are well and thanks for the help in advance as well as the ongoing maintenance to Behavior Designer.

Please let me know if these repo steps are not clear and I'd be happy to provide more details or send over a video.

Steps:

1. From a new scene, create a new GameObject and rename it to 'MyTestObject'
2. Add a BehaviorTree component to 'MyTestObject'
3. Add a few tasks/nodes into the behavior tree (idle task, log task, sequence, etc)
4. From the Behavior Designer editor, also add a few local variables to the BehaviourTree. These can be anything, but lets make them bool for simplicity. Name the variables A and B.
5. Drag the GameObject into the project view to create a new prefab.
5. From the Hierarchy, Select the 'MyTestObject' GameObject.
6. Scroll to the Behavior Tree Component Inspector adjust the value of Variable A to true by selecting the toggle beside the Variable A.
7. From the Project view, double click the MyTestObject prefab asset to enter the "edit prefab" editor state.
8. Add an additional task (lets add a log task) to the Behavior Tree.
9. Exit the "Edit Prefab" state
10. From the Hierarchy, select the MyTestObject.

Observed
Notice that the Behavior Tree of the MyTestObject in the scene does not reflect the changes just made to the MyTestObject prefab asset.

Once the local version of the BT is altered, the instances of the BT do not reflect changes made to their their prefab asset.

Expected
Instances of the prefab should reflect the changes made to the origin prefab asset.

Notes
This issue presents a challenge with the workflow as we need to manually go scene by scene to revert the objects and then reapply variables values to instances.

This can be resolved, by select 'reverting' the changes make to the instance of the MyTestObject in the scene. This would destroy any changes made to the instance of the BT (In this case the local version of the variables).

We have a workaround for this were we have a separate class that that writes the variables during runtime, before the BT starts. With this we would leave the variables blank (so to ensure the BT does is not changed).

Perhaps BT variables should be read only, similar to the functionality of the Tree editor (View Mode Only).

Ideally, the BT instances should update to reflect changes to the source asset. It is understood this may hard to resolve if local variables are changed, etc.
 
Last edited:
Are you using JSON or binary serialization? Have you tried switching it?

Prefabs update based on the dirty fields. When the serialization is persisted Unity checks to determine if any of those dirty fields have changed and will update the instance based on that. Unfortunately the prefab system is a black box besides that and it doesn't give many callbacks so this may be a feature request for Unity.
 
Top