#Syncvar not working
17 messages · Page 1 of 1 (latest)
Use OnStartServer
Override
Or send command from client
[Command]
If u have data on server use OnStartServer
if u have data on client use command
Idk what do u need
So u need to send data from client to server?
public class SomeClass : NetworkBehaviour
{
[SyncVar(hook = nameof(HookUpdateData))]
private string someSyncVar;
/// <summary>
/// CLIENT
/// </summary>
/// <param name="_"></param>
/// <param name="newData"></param>
private void HookUpdateData(string _, string newData)
{
// do something when client get updated `someSyncVar`
}
/// <summary>
/// CLIENT
/// </summary>
public override void OnStartClient()
{
SomeCommandFromClientToServer("SOMEDATA");
}
/// <summary>
/// SERVER
/// </summary>
/// <param name="data"></param>
[Command]
private void SomeCommandFromClientToServer(string data)
{
someSyncVar = data;
}
}
Is it what you need?
OnStartClient -> SomeCommandFromClientToServer -> HookUpdateData
You get client data in OnStartClient, then send command to server to update syncvar
Then syncvar triggers hook on clients with new data
Sorry im too sleepy to understand 
If you send command from client and set syncvar to new value, yes, you could get this value with GetComponent<T>
Yes
Yes