2
\$\begingroup\$

I was trying out the new Unity networking and I added the SyncVar attribute to one of my variables to be synced. I also have a property to get/set the variable and update the visuals when set. I set the "hook" variable in the SyncVar so the property is used and visuals are updated properly (or that was the idea, since it gives an error :P)

[SyncVar(hook = "set_Tapped")]
private bool _tapped;
public bool Tapped
{
    get { return _tapped; }
    set { _tapped = value; UpdateRotation(); }
}

Now however I get an error in the console:

UNetWeaver warning: SyncVar [_tapped] set from within property function [System.Void Card::set_Tapped(System.Boolean)]. This will not set dirty flags.

How should this be handled? I could just make a set method myself (not using properties), but is there a better/nicer way?

Thanks!

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

I have the same problem.

Given this unnecessarily complex post and this possibly useful but awfully long manual page, it's safe to say that just rewriting it to be a normal function instead of a setter, would be orders of magnitude easier than any other solution.


That being said, here's an alternative approach, that uses SyncVar:

[SyncVar] private Status status = Status.Free;
private Status prevStatus = Status.Free;

void Update ()
{
    if (status != prevStatus)
    {
        DoStuff();
        prevStatus = status;
    }
}

Over Rpc, this has the advantage of being "automatically" synced to new clients, at the expense of being slightly less obvious/readable/clear.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .