Variables are weirdly shared in external BTs ?

Berza

New member
Hi!
I am just beginning to use Behavior Designer.

My idea was to keep trees small and clean by changing External BTs for people in my game (pedestrian decorations).
Lets say, some are performing group discussions, while others are shopping, or just wandering around.

Every person was supposed to start without any tree, only plugged in shared variables, like MyGameObject and MyAnimator.
Then i intended to plug in external BTs with proper behaviors and interchange them as needed, to keep the trees nice and small.

When i tried to inject all of my people with a simple External BT of "Play Random Idle Animation" (Smoke a cigarette, check the phone etc.) it started to break, as only ONE person was performing anything, all other persons were referencing MyGameObject and MyAnimator to that ONE person.

Own trees, on each prefab have those 2 shared variables plugged, and external BT also have those 2. According to documentation, i hoped that each one of them would "copy" this BT into itself, and use its own variables to play animations.

I tried also version with GetComponent at start, same result, as only one person is playing animations.
I tried version with GetComponent in update (just out of hope :( ), same result, as only one person is playing animations.
Having variables in own Tree component hoping they will sync with External BT (i believe they synced the other way around... )
Grabbing components from own class attached to GameObject (i think it still cached component on wrong GameObject ).

Any help or advice how to share single instances of External BTs on multiple prefab instances on the scene and switching them dynamically? Or should i change my approach to the subject?
 
After you instantiate the prefab the gameObject variable will point to the current instance. When the behavior tree is enabled the external tree is then copied to the current instance. I'm not sure how you are creating the tree or referencing the objects but when you set the variable you should be sure you are setting it on the actual instance instead of the object stored in the project file.
 
Thanks for your reply.
We did plug the External BTs onto instances of our persons, not their prefabs.

Anyway, a solution was pretty simple, once found:
We are Instantiating a copy of EBT before assigning it.

var treeCopy = Instantiate(_myTree);
treeCopy.Init();

and pass it onto prefab instance, that works now correctly.

A great package by the way. I just could hope that tutorial assets are better described, for example have their "comment" sections filled up. :)

Best regards
Krzysztof
 
Top