[Suggestion] Allow void type for SyncVar hooks

The current implementation of SyncVar event generation forces the user to pass a parameter to the referred function. However there are many situations when a more generalized event might be useful. For example an AppearanceChanged function which rebuilds a mesh based on multiple parameters.

I was unable to find an easy workaround for this issue. It seems the network compiler finds the first instance of a function and will ignore all others, meaning overloaded methods like the example below wont work.

[SyncVar(hook = “SyncVarEvent”)]
public short paramA;

//this param throws an error
[SyncVar(hook = “SyncVarEvent”)]
public Vector3 paramB;

public void SyncVarEvent(short param) { SyncVarEvent(); }
public void SyncVarEvent(Vector3 param) { SyncVarEvent(); }
public void SyncVarEvent()
{
}

The value passed to the Hook is the value the SyncVariable is changed to. If you don’t need that value, don’t use it, but when you specify a Hook function for a SyncVariable, this variable will not be synced automatically. You have to change the value inside the hook for the variable to be synced across the network.

//x will be synced across the network via the hook function
[SyncVar(hook = "func1")]
float x;

void func1(float newX) {
    x = newX;
}

//y will be synced automatically
[SyncVar]
float y;

//z will NOT be synced
[SyncVar(hook = "func2")]
float z;

void func2(float newZ) {

}
1 Like