SyncVars in GameManager Not Working

In my game, I have a lot of singletons that more or less run the game’s scene to scene state and logic. To use Host Migration, some of the variables in these singletons will need to be in SyncVars. How does this work for objects that aren’t spawned?

I read about scene objects in the manual, but that doesn’t seem to work right in this case. I have a NetworkIdentity on my GameManager object that’s created in my first scene and has DontDestroyOnLoad() in its Awake(). When running a multiplayer game, the client doesn’t get the updated values for variables that are SyncVars.

Does anyone have a suggestion?

One thing to note is that SyncVar variables with hooks are set to the default value for any client that logs in. So, you would need to have the class extend the NetworkBehaviour class, and override the OnStartClient method. For example:

using UnityEngine;
using UnityEngine.Networking;
using System.Collections;

public class Health : NetworkBehaviour {
  
    public const int maxHealth = 100;

    [SyncVar(hook = "OnHealthDecreased")]
    public int currentHealth = maxHealth;

    void OnHealthDecreased(int health) {
        //This next line is to update health for clients
        currentHealth = health;
    }

    public override void OnStartClient() {
        OnHealthDecreased(currentHealth);
    }
}

Also, what are your SyncVar variables? As stated in the manual, only certains primitives and objects can have the SyncVar attribute: http://docs.unity3d.com/Manual/UNetStateSync.html

Thank you. All good points. The SyncVars are floats without hook functions. They’re updated on the server and should propagate out to the client. I run the server in a standalone build and the client in the editor so I can watch the variables in the inspector. The variables don’t change at any point while watching them in the inspector. Could my test be flawed?

Try increasing your loglevel on NetworkManager to see if the server is sending the SyncVars and if the clients are receiving them.

The SyncVars in my GameManager are being sent by the host but are not received by the client. Other SyncVars, ones not in scene objects, are being sent and received correctly. Could there be some undocumented requirement for scene objects in order for them to work correctly, or perhaps this is a bug?

@ did you find a solution for this?
I can’t see figure out how to deal with NetworkBehaviours already existing in the scene as opposed to spawned ones.