Serializing the object states (visible / invisible)?
ruse
✭
So there are character objects, in the beginning, i want them to be visible or invisible through a random variable and serialize it to everyone. For example, if the variable is equal to 1, the first character should be visible and the other one should be invisible. The avatars are for setting the animator avatar of the character.
The code is below;
-----------------------------------------------------------------------------------------------------------------------------------------------------
That should work i guess but it doesn't, the states are not serialized.
So, any idea to fix this issue?
The code is below;
Animator anim; public Avatar char1; public Avatar char2; public GameObject char1Obj; public GameObject char2Obj; void Start () { anim = GetComponent<Animator>(); randomChar = Random.Range(1, 3); if (randomChar == 1) { char1Obj.SetActive(true); char2Obj.SetActive(false); anim.avatar = char1; playerRole.mannequin = char1Obj; } else { char2Obj.SetActive(true); char1Obj.SetActive(false); anim.avatar = char2; playerRole.mannequin = char2Obj; } } public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.isWriting) { stream.SendNext(char1Obj.activeSelf); stream.SendNext(char2Obj.activeSelf); } else { char1Obj.SetActive((bool) stream.ReceiveNext()); char2Obj.SetActive((bool) stream.ReceiveNext()); } }
-----------------------------------------------------------------------------------------------------------------------------------------------------
That should work i guess but it doesn't, the states are not serialized.
So, any idea to fix this issue?
0
Best Answer
-
You don't hide the object, you're disabling it.
A while ago, we changed PUN to not serialize disabled objects, which fits best with Unity's approach to inactive objects.
You could either just disable the renderer or have a proxy/stand-in object that stays active but wraps your character (which can be enabled or disabled as needed then).5
Answers
-
following.. I am trying to achieve same goal0
-
You don't hide the object, you're disabling it.
A while ago, we changed PUN to not serialize disabled objects, which fits best with Unity's approach to inactive objects.
You could either just disable the renderer or have a proxy/stand-in object that stays active but wraps your character (which can be enabled or disabled as needed then).5