SharedString provided to a BehaviorTreeReference are not properly retrieved in a List<SharedString>

Noxalus

New member
Hello,

I think I found a pretty weird bug.

My goal is to transmit a variable value to a BehaviorTreeReference from its parent. The BTR loads a simple tree with only one action:

1637664218459.png

The code for this action is here:

C#:
using UnityEngine;
using BehaviorDesigner.Runtime;
using BehaviorDesigner.Runtime.Tasks;
using System.Collections.Generic;
using System.Linq;

public class TestAction : Action
{
    [SerializeField]
    private List<SharedString> _list;

    [SerializeField]
    private SharedString _string;

    public override void OnStart()
    {
        Debug.Log($"Print list: {string.Join(", ", _list.Select(item => item.Value))}");
        Debug.Log($"Print string: {_string.Value}");
    }

    public override TaskStatus OnUpdate()
    {
        return TaskStatus.Success;
    }
}

So I just print serialized field.

From above, I have this:

1637664062028.png

So what I expect is to see:

Print list: VALUE, 42
Print string: VALUE

But what I get is:

1637664195322.png

Did I do something wrong?

PS: I use Behavior Designer version 1.7.1 with Unity 2020.3.21f1.
 
You will need to create a SharedStringList variable instead of List<SharedString> and propagate that to the referenced tree. When the variable reference is being copied it is not going to look through all of the child objects for performance reasons.
 
You will need to create a SharedStringList variable instead of List<SharedString> and propagate that to the referenced tree. When the variable reference is being copied it is not going to look through all of the child objects for performance reasons.
Thank you for the quick answer! If I do that, I won't be able to have constant values defined directly on the action like the "42" in my example, and I need that because I could have the same action multiple time in the same external behavior tree. :cry:

If I would like to look through all of the child objects of a List<SharedString> for a specific case, how could you do that?
 
Right now this will take modification within the Behavior Manager. The variables get populated within the AddToTaskList method.
 
Thank you again Justin, I looked at the code but after some more tests, it appears that if we have the same variable name in the tree loaded by the BehaviorTreeReference, the value is properly set and can be used in a List<SharedString>. I prefer to let the code untouched and use this solution instead! (y)
 
Top