Hello,
I make my first networking game, and I have an isue with the syncvar attribute, I Think I miss one think.
I have my variable here
[SyncVar(hook="OnObjectiveChange")]
private int m_nObjectiveId;
I modify it here (Only server modify the value)
public void SetObjective( int nObjective )
{
if( isServer )
{
m_nObjectiveId = nObjective;
}
}
On my client I go inside my hooked function
private void OnObjectiveChange( int nObjectivId )
{
// Do stuff Change Hud
Debug.Log( "Test Hook on client, new objective : " + nObjectiveId );
...
}
I have on my client console

But on my element :

For informations, my element is a Registered Spawnable element, I use it to share gameplay information between my clients.
I could fix it by assigning my variable in the hooked function, but it’s not the good way, So if someone could explain me what wrong, it would be very nice.
Thanks!
I found this similar question
The answer would be that hook function works as some kind of override, so we have to manually assign the value on clients.
In this case, the documentation could be more explicit here :
https://docs.unity3d.com/Manual/UNetStateSync.html?_ga=2.209780693.159795064.1505993960-716317901.1505134071