Request: Recursive Variable References and a simple Copy&Paste

rollin

New member
Hello!


#1) Let's start with the simple one:
Allow Ctr+C and Ctr+V to copy paste Variable strings from the Behaviour Designer editor window.
This drives me crazy every time I have to re-type it into notepad to be able to correctly remember the correct typing


#2) The 2nd is more important but more difficult to explain:
When using a Behaviour-Tree-Reference-Task I'm able to set kind of a variable mapping. What actually happens is that all(?) instances of the relevant variable in the references BT are replaced with the mapped one (but the variable still exist in the variables list).


My problem occurres when referencing another BT inside the first referenced BT
Like: [Main BT] - [Ref1 BT] - [Ref2 BT]
This is the most simple test case but of course this applies to any reference depth > 1


Again I set a variable mapping from the already mapped var in [Ref1 BT] to the one I want to override in [Ref2 BT]


What should happen:
The variable from [Main BT] will replace all instances of the mapped var in [Ref1 BT], then all instances of the mapped var in [Ref2 BT] will also be replaced by this var from [Main BT]


What does happen:
The mappings are not propagated recursively from [Main BT] to [Ref2 BT] but instead its only [Ref1 BT] to [Ref2 BT] and [Main BT] to [Ref1 BT]. For this use case [Ref2 BT] ends up with a 'dead' variable as the orignial - unmapped [Ref2 BT] var is just a placeholder that needs to be mapped to a var that actually holds a value (the one from [Main BT])


What should be changed:
The mapping should run recursive by first replacing the vars in [Ref1 BT] including(!) the vars in the Behavour-Tree-Reference-Task. Then propagate down from [Ref1 BT] to [Ref2 BT] to [RefN BT].


This is imo a very important feature as I often use very abstract BTs which bit act like compound Tasks. In these cases I want to have a specific scope for my vars. And because I often end up having multiple levels of referenced behaviour trees this leads to the described problem.



Kind regards
 
1. You should be able to copy and paste the variable names - are you running the latest version? I just tried to copy/paste the name and it worked.

2. The variables should propogate down from all of the external trees. Can you create a small repro scene so I can see a concrete example of what you are referring to?
 
Hi Justin,

I've attached an simple example. It should log the growing strings twice but for me it does it only once and the 2nd time is 'null'. If I check the mapped variables during play-mode I see [Ref2 BT] is mapped to the [Ref1 BT] var and the [Ref1 BT] var is mapped to the [Main BT] var.

I'm using unity 5.6.7. Maybe that's a Problem?
 

Attachments

  • RecursiveVariableMappingExample.unitypackage
    3.4 KB · Views: 1
The current version of Behavior Designer requires Unity 2017_3+ so you are getting version 1.6 with Unity 5.6.7. I think that the copy/paste problem did exist in that version.

Thanks for that package. When I tried it it outputted (null) and then progressively added to the HeyHo string. Based on your tree this is expected, though I can think about it some more to determine if it needs to be changed. When ReferenceVars_Main loads the MyRefVar2 string will be replaced with RefVar2, so it doesn't get a chance to replace MyRefVar2 in the ReferenceVars_RefRef tree.
 
It should output twice (as two log-nodes) the first grows the HeyHo string and the 2nd always null.

For me this is a show stopper atm.
To save time during development I have multiple levels of referenced behavior trees.
Of course I could work around the issue by copy-pasting the same sub-section where ever I need it but changing anything afterwards will be time consuming.

It would be awesome If you could implement (at least as option) this behavior.
However, also intuitively I though that the BT-reference-task changes all vars inside this referenced tree based on the variable mappings I set there and not exclude the BT-reference-tasks it comes by as this would be the only exception, wouldn't it?
I can't see a reason why it should map the var in e.g. a log-task but not in a bt-reference task.

Even if this is something that automatically emerges from a technical point of view in your code I think it's worth the effort supporting this "recursive"-thing.

On a side node: The way you handle the vars in Behavior Designer is very unique and makes this assets so valuable in my opinion and the reason why I chose to buy BD.
Propagating vars through multiple reference-levels is just part of this same great concept that allows you to build kind of prototype BTs that you then feed the vars as you wish. I would call it "tree-based-blackboards" which is something very hard to find in any implementation I saw yet.

To think this a bit further it would be perfect if one could setup the mapping of vars with two shared-var-dropdowns - completely eliminating typing strings!
 
Your image shows the same result I get from the test I send you, showing the described problem.

The _wanted_ result should show each output twice like:
(null)
(null)
HeyHo
HeyHo
HeyHoHey
HeyHoHey
etc.

That being said: The test is not perfectly setup to ensure that each string logs exactly twice because of the multiple 'Wait'-tasks that are all set to 1sec.
So the relevant part of the _wanted_ result is that there is no (null) output except for the first two
 
So what do you think / plan?

As I need to go on I'll implement a fix meanwhile myself.

And btw. Could you tell me where I can download the Source of the latest unity 5 compatible version (1.6?)
The package I downloaded only included 2017 and 2018

Cheers


Edit: ok now it gets confusing.
Out of curiosity I just set up the whole thing with 2017 and used the runtime sources from today instead of the dll
Also I'm using this fix to remove the null-ref error: https://opsive.com/forum/index.php?threads/another-null-ref-exception-in-1-6-2.1259/#post-6200

Now both referenced trees map to the 'MyRefRef' var of the [Ref2 BT] and the Main tree maps to the 'MyRef' var of the [Ref1 BT] ... Which is kind inverse of what I get in unity 5 (with 1.6.0 I guess) and in general pointing in the wrong direction?! Or am I totally missing the concept of this feature?!

Also now:
- the MyRef var first gets the value of the Ref var (from [Main BT])
- the MyRefRef var first gets the initial value of the MyRef var from [Ref1 BT]
- the MyRef var grows the string bc the [Main BT] var is now mapped to it.
- the Ref var from [Main BT] doesn't even exist anymore in the list of variables during play mode

Edit2: ok it seems to be the line:
behaviorTree.behavior.GetBehaviorSource().UpdateVariableName(sharedVariable, (overrideField.Value as NamedVariable).name);

----
I'll try to solve this the way I need it and port it over to 1.6.0
 
Last edited:
Hi Justin,

I found a solution...
One might argue if it's by design or simply a bug.
However, I think the most common (and intuitive) way is the recursive way I have described above.

So the 'problem' lies within the BehaviorManager.AddToTaskList() method

you do the following:

C#:
if (task is BehaviorReference)
{
   (...)
}
else
{
   (...)
}

and only in the 'else' case you replace/map vars by calling 'OverrideFields()'!
So all tasks (like the 'Log' tasks in my example) map the vars and only for BehaviorReference tasks you don't do it.
As I guessed - and that's all.

The 'problem' is fixed by copying the call to 'OverrideFields()' also into the 'if' case (or by moving it completely out and in front of the 'if-else-block')

This for example would be a solution:

C#:
if (task is BehaviorReference)
{
   if (data.overrideFields != null)
   {
      OverrideFields(behaviorTree, data, task);
   }
   (...)
}
else
{
   (...)
}

Also I removed the aforementioned line as I don't want it to inverse map (which is imo very awkward or I don't get the point):
C#:
behaviorTree.behavior.GetBehaviorSource().UpdateVariableName(sharedVariable, (overrideField.Value as NamedVariable).name);

So I hope I could help you and anyone having the same issue as I did.

And again: can you tell me where I can download the latest unity 5.x compatible runtime source, please!

Cheers!
 
Top