What is the best workflow for shared behaviors and prefab variants?

dipyalov

New member
We are currently reusing behaviors via External Behavior Tree assets and making several prefab variants (Unity 2019.4) of enemies, with some SharedVariables tuning.

And currently we are facing the following problems:
- External behavior tree gets embedded into Behavior Tree component - which adds extra size to the prefab.
- Any shared variable modification snapshots all the shared variables and generally doesn't play well with prefab variants.

So what is the best proposed way to achieve our goals - to get reusable behaviors and to have shared variables tuned in prefab variants? It is OK if some coding is required.
 
- External behavior tree gets embedded into Behavior Tree component - which adds extra size to the prefab.
Can you expand on this problem? When you assign the external tree it doesn't serialize to the prefab.

- Any shared variable modification snapshots all the shared variables and generally doesn't play well with prefab variants.
Have you tried switching to JSON serialization? This generally works better with Unity's prefab system.
 
Can you expand on this problem? When you assign the external tree it doesn't serialize to the prefab.
I have the following setup: External Behavior Tree is referenced in prefab. Then there is a variant of this prefab. And in some cases when I modify the tree via Designer - the full tree gets serialized in the prefab variant. I need some time to determine the exact order of actions which leads to this situation.


Have you tried switching to JSON serialization? This generally works better with Unity's prefab system.
We are experimenting with Binary and JSON now. Binary has some issues with too many prefab modifications written in the asset. But the main problem is that this setting is not project-wide, but machine-wide, so you may not force JSON serialization for the whole project.
 
OK, I'm trying to reproduce the problem and having a very strange behavior.
What I've done:
- created an empty project from scratch
- created a simple External Tree with GameObject Shared Variable (and few scalars)
- created a game object, added Behavior Tree component and then created a prefab from it.
- then I entered prefab editing mode, assigned the External Tree to Behavior Tree component, created a child Game Object and assigned it to a shared variable
- then clicked Save in the scene view

What I got serialized seems wrong - reference to Game Object is set to 0:
2020-09-21_21-16-01.png
 
OK. It seems like setting the value from picker doesn't work in prefab editing mode. See the blue icon - this means that this is not the inner object, but an object from Scene. Main Camera is also not present in prefab.
2020-09-21_21-35-57.png
 
Ah, I see.. I think that everything is working correctly in that case.

When you have the external behavior tree set you can override the external behavior tree variables. These variables are then saved to the prefab. The references to scene objects from prefabs will not be saved because you cannot save a scene object from a project level asset. This page has more info: https://opsive.com/support/documentation/behavior-designer/referencing-scene-objects/
 
Ah, I see.. I think that everything is working correctly in that case.

When you have the external behavior tree set you can override the external behavior tree variables. These variables are then saved to the prefab. The references to scene objects from prefabs will not be saved because you cannot save a scene object from a project level asset. This page has more info: https://opsive.com/support/documentation/behavior-designer/referencing-scene-objects/

Thank's for the reply. I've researched our workflow and determined one major issue that prevents what we try to do.
I've created a separate post: https://opsive.com/forum/index.php?threads/bug-external-tree-gets-copied-to-prefab.3939/#post-19395
 
Top