Lists of SharedVariables

DirtyHippy

New member
I have a simple action task that has an enum and a sharedfloat. It simply looks up the value based on the enum and puts it in the shared var. Since I tended to use multiple of these in a sequence, I figured I would create a separate task with a little serializable list of these where each serializable entry was simply the enumeration and a sharedfloat.

However, this doesn't seem to work - I don't see the values changing in the behaviour variables list.

So then I figured there must be some sort of mapping going on, probably via reflection on startup, to identify these fields. So I looked in the assembly source and tried this in OnAwake () for this node (where MyVariableEntries are a simply class with an enum and a SharedFloat (called TargetVariable).

Code:
            var behaviourSource = Owner.GetBehaviorSource ();
            for (int index = 0, count = MyVariableEntries.Count; index < count; index++)
                MyVariableEntries [index].TargetVariable.InitializePropertyMapping (behaviourSource);

But this doesn't appear to work either when I assign something to TargetVariable. Is there a way to do this or should I just stick to single nodes?
 
I'm not completely following what you are doing - what does your task look like?
 
Something like this:

Where AgentSetVariable.SetVariable basically switches off the enum and populates the target variable with the result (from internal non-behaviour tree sources).

Code:
    public class AgentSetVariables : AgentActionBase
    {
        [Serializable]
        public class AgentVariable
        {
            public MyEnumType VariableType;
            public SharedFloat                    TargetVariable;
        }

        public List <AgentVariable> Variables;

        public override void OnAwake ()
        {
            var behaviourSource = Owner.GetBehaviorSource ();
            for (int index = 0, count = Variables.Count; index < count; index++)
                Variables [index].TargetVariable.InitializePropertyMapping (behaviourSource);

            base.OnAwake ();
        }

        public override TaskStatus OnUpdate ()
        {
            for (int index = 0, count = Variables.Count; index < count; index++)
            {
                var variable = Variables [index];
                AgentSetVariable.SetVariable (AgentNpc, variable.VariableType, variable.TargetVariable);
            }

            return TaskStatus.Success;
        }
    }
 
When you assign the TargetVariable what happens? Does the TargetVariable have a mapping created? The mapping will be created by populating the mGetter and mSetter fields. You'll probably want the runtime source to inspect these values:

 
Top