Node Event and Variable map

oktagondev

New member
Hello, I have two questions.

First, I know that is possible to get all variables on a tree, can I auto assign variables through code?
Supose I set a sharedvariable as IsShared = true, then I want to map It to the tree variable, is It possible?

Second, there's a event or something similar when you create a node? I know I could use OnDrawGizmos, but It is Called only on a monobehaviour object, If I edit a tree that is a asset file, OnDrawGizmosis is not Called.

Thanks.
 
First, I know that is possible to get all variables on a tree, can I auto assign variables through code?
Supose I set a sharedvariable as IsShared = true, then I want to map It to the tree variable, is It possible?
Yes, you can use BehaviorTree.SetVariable: https://opsive.com/support/document...es/accessing-variables-from-non-task-objects/

Second, there's a event or something similar when you create a node? I know I could use OnDrawGizmos, but It is Called only on a monobehaviour object, If I edit a tree that is a asset file, OnDrawGizmosis is not Called.
Are you referring at edit time or design time? There are no editor events sent but you could use the constructor for when the task is created.
 
Thanks for the answer, the first one worked perfectly.

About the node constructor, could you exemplify?
What I meant is when you are creating a tree on the editor, so when you create a Action for example, a event is called, OnNodeDrawn for example, something like that.

Thank for answering.
 
By constructor I mean the standard c# constructor for a new task. I'm not sure if that fits your use case though.
 
The constructor worked, the only problem is that Owner is set after the custom task constructor. There's another way to get the tree and its variables from the task ?
 
Since the task will only be added when the editor is open, the BehaviorDesignerWindow.instance field is populated. From there you can get the active tree with:

Code:
BehaviorDesignerWindow.instance.ActiveBehaviorSource

The BehaviorSource contains all of the data about the tree and has the variable methods that you can use.
 
Top