- Home /
[pun] Vector3 synh problem
Hello. I need to sync 2 values:
public Vector3[] actSkillTrg = new Vector3[4]; //active skill target(s)
public int skillCD = 0; //active skill cooldown
I can't sych GameObjects, so I use Vector3 to define targets. So I use OnPhotonSerializeView to synh both. Then I have this in OnDisable():
if (bGoldGet) {
gameObject.GetComponent<stats>().actSkillTrg[0] = new Vector3(3f,3f,3f); //3rd player himself
gameObject.GetComponent<stats>().skillCD = 3;
}
bGoldGet = false;
and this in GoldControl():
public void p3GoldGet()
{
if (pl3.GetComponent<stats>().actSkillTrg[0] != Vector3.down)
{
print("pl3 gets gold!");
pl3.GetComponent<stats>().gold++;
pl3.GetComponent<stats>().actSkillTrg[0] = Vector3.down;
}
if (movEnd && pl3.GetComponent<stats>().skillCD!=0) { pl3.GetComponent<stats>().skillCD--; }
}
Problem is: int skillCD works fine, but Vector3[] actSkillTrg isn't synchronizing. Like if I put "print(pl3.GetComponent().actSkillTrg[0]);" in Update() it always prints "(0,-1.0,0)" on Host's pc, but prints (3.0,3.0,3.0) on Client's. Why could it be??
I use some invoke delay between OnDisable() and GoldControl().
where is the code where you actually sync your stuff?
In general you should make one consideration when implementing sync: Does the value change often (multiple times per second) or only a few times once every few seconds?
if the latter is the case do not use OnPhotonSerializeView. Just use an RPC. The latter is easier to implement for now-and-then sync calls - especially when it comes down to saving bandwidth.
are you sure that the client never sets a value on it's own and that it only uses the stream values?
Answer by miha4406jp · Oct 22, 2021 at 09:20 PM
Well, I checked literally everything, but problem was in PhotonView itself.
Changing PhotonView option from "Reliable delta compressed" to "Unreliable on change" fixed issue.
If anybody has explanation, I'd like to hear.
Your answer
