Duplicating behavior trees

Qeaua

New member
Hi,

I'm trying to duplicate a behavior tree and use it for other actors, but with minor task editing. I read while researching the subject that external trees are the way to do it, however, when I tried exporting and using an external tree, I got 'NullReferenceException' errors relating to some SharedVariables.

Questions:
  • Are external trees the only way to copy/paste/edit behaviors between actors?
  • Are SharedVariables incompatible with external trees? If not, how to best address these errors?
 
If you just want to duplicate the behavior tree you can copy the behavior tree component and paste it to the new object. The shared variables will also be copied over but depending on where you copied the reference may need to be updated. I'm guessing that this is why you are getting the exception that you are.

External trees are recommended for this situation though since they will all point to the same objects. You can use shared variables in the external trees. If you want to reference a local scene object you should set that reference within the behavior tree component that has the external tree reference.
 
Hi,

I hope it's okay reviving this thread.

Shared variables are working fine but I'm starting to run into a few situations where I need to use custom actions with local variables. However, each time I run the game, the variables inside the external tree get nullified. How should I navigate this?

using BehaviorDesigner.Runtime.Tasks; using MoreMountains.Feedbacks; public class PlayFeedback : Action { public MMFeedbacks feedback; public override void OnStart() { feedback.PlayFeedbacks(); } public override TaskStatus OnUpdate() { return TaskStatus.Success; } }

1666642428406.png
 
Last edited:
You can either get a reference to that task using FindTask and assigning the reference at runtime or you can create a new MMFeedbacks SharedVariable and use the variable system:

 
Top