Problem to update a custom sharedvariable

Sylmerria

New member
I have a problem to update variable value after the first setup.

Custom variable
C#:
namespace HMH.BehaviorDesigner
{
    [System.Serializable]
    public class SharedEntity : SharedVariable<Entity>
    {
        public static implicit operator SharedEntity(Entity value)
        {
            return new SharedEntity { mValue = value };
        }

        public static implicit operator Entity(SharedEntity value)
        {
            return value.mValue;
        }
    }
}

The first time the code runs the variable is added, but the second time the variable is not updated and stays with his first value.
Whatever what I try, this variable is not updated. And I'm sure the variable is good because the name of the behavior is well setted.


C#:
                         var btComponent = new BehaviorTreeComponent
                         {
                             BehaviorTreeSocle    = _behaviorTreeFreeList.RemoveLast(),
                             ExternalBehaviorTree = dataManager.GetBehaviorTree(spawnAgentInit.BehaviorTreeType),
                             BehaviorTreeId       = spawnAgentInit.BehaviorTreeType
                         };

                         btComponent.BehaviorTreeSocle.BehaviorName     = "Agent " + entity;
                         btComponent.BehaviorTreeSocle.ExternalBehavior = btComponent.ExternalBehaviorTree;
                         var test=(SharedVariable)btComponent.BehaviorTreeSocle.GetVariable("AgentEntity");
                         test.SetValue(entity);
                         //test 2 not working either
                         //btComponent.BehaviorTreeSocle.SetVariable("AgentEntity",test);
                         //test 3 not working either
                         //btComponent.BehaviorTreeSocle.SetVariableValue("AgentEntity", (SharedEntity)entity);
                         btComponent.BehaviorTreeSocle.enabled          = true;
                         btComponent.BehaviorTreeSocle.EnableBehavior();
 
Last edited:
Try setting the Value property, though it should be doing the same thing. Beyond that does it work correctly with a variable that is built in?
 
Try setting the Value property, though it should be doing the same thing.
It's what the test does, isn't it ?

Beyond that does it work correctly with a variable that is built in?

You mean set a variable directly into the action class ?
 
By using a built in variable I meant using a variable of a different type other than Entity just to make sure it's not something within the Entity struct causing the issue. Basically making sure your other logic is correct and it's something specific to Entity.

Another way to debug this would be to import the runtime source and place a breakpoint when the value is set. This will allow you to see exactly what is getting set and when.
 
I found it, even if I don't understand why maybe you can explain me it.

I had `ResetValuesOnRestart` set to true, so my variable was reset, that's logic but why the old one remains I don't know :/
 
Top