Gameobject/Transform network sync is null

sondirn

New member
I'm using the source code for behavior designer and replaced the old Unet with Mirror. When enabling network sync on variables such as vector3, bools etc they all work as expected. However, when I try to network sync Gameobject/transform variables I get a null error.

I simplified my code below but in a nutshell it looks like this.


C#:
public SharedGameObject target;

public override void OnAwake(){
    target = (SharedGameObject)Owner.GetVariable("current target");
}

public override TaskStatus OnUpdate(){
    target.Value = //Set the target here;
    return TaskStatus.Success;
}

When setting network sync to true I get a null reference error specifically this below

NullReferenceException: Object reference not set to an instance of an object
BehaviorDesigner.Runtime.SharedVariable`1[T].set_Value (T value) (at Assets/Behavior Designer/Runtime/Variables/SharedVariable.cs:133)
BehaviorDesigner.Runtime.Tasks.SpoonBehaviors.AI.Search.OnUpdate () (at Assets/Runtime/Networking/BehaviorTasks/SpoonBehaviors/AI/Search.cs:33)
BehaviorDesigner.Runtime.BehaviorManager.RunTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32 stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus previousStatus) (at Assets/Behavior Designer/Runtime/BehaviorManager.cs:1261)
BehaviorDesigner.Runtime.BehaviorManager.Tick (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree) (at Assets/Behavior Designer/Runtime/BehaviorManager.cs:1072)
BehaviorDesigner.Runtime.BehaviorManager.Tick () (at Assets/Behavior Designer/Runtime/BehaviorManager.cs:1020)
BehaviorDesigner.Runtime.BehaviorManager.Update () (at Assets/Behavior Designer/Runtime/BehaviorManager.cs:981)


However, I don't get any errors when NetworkSync is set to false...
Again this only happens with SharedGameObjects and Shared Transforms

Anyone know why this could happen?
 
Line 133 is different for me as it doesn't point to setting the value. What is the null object?
 
Line 133 is different for me as it doesn't point to setting the value. What is the null object?

The full function is below
Code:
public T Value
        {
            get { return (mGetter != null ? mGetter() : mValue); }
            set
            {
                var changed = NetworkSync && !mValue.Equals(value); //Line 133
                if (mSetter != null) {
                    mSetter(value);
                } else {
                    mValue = value;
                }
                if (changed) { ValueChanged(); }
            }
        }

Although what I am noticing is this. When putting a breakpoint where I modify the sharedVariable value

public SharedGameObject target;

public override void OnAwake(){
target = (SharedGameObject)Owner.GetVariable("current target");
}

public override TaskStatus OnUpdate(){
target.Value = //Set the target here;
return TaskStatus.Success;
}

Visual studio is telling me that the target variable is null. I have it set to be empty in the behavior editor. I tested this with both network sync enabled and disabled. Both times the "target" variable is set to null automatically like planned. Only issue is when network sync is on
 
Thanks, I see. Try changing that line to:

Code:
var changed = NetworkSync && mValue != value;
 
Oops, that line should be:

Code:
                var changed = NetworkSync && ((mValue != null && !mValue.Equals(value)) || (value != null && !value.Equals(mValue)));
 
Top