Synchronizing GameObjects with Players

Options
Hi. I'm trying to sync some objects with my players. Let me explain a little.

I made a PoolManager using DefaultPool and using IPunPrefabPool interface which on Awake instantiate some objects. After players are spawned on scene, I have a manager which takes some objects from the pool and they are parented to the first line of my matrix https://prnt.sc/rc9hi7 - like in this picture.
// Hardcoded spawn
powerUpTile = PoolManager.Instance.PullObject("Trap", lines[0].container[pos[0]].transform);
powerUpTile.transform.localPosition = new Vector3(0f, 0f, 0f);

for (int i = 1; i < pos.Count; i++)
{
    powerUpTile = PoolManager.Instance.PullObject("PowerUp", lines[0].container[pos[i]].transform);
    powerUpTile.transform.localPosition = new Vector3(0f, 0.5f, 0f);
}

Every "tile" has a PhotonView component attached, and after they are spawned on their parent as a child OnEnable is called.
if(PhotonNetwork.IsMasterClient)
    PhotonNetwork.AllocateSceneViewID(GetComponent<PhotonView>());

object[] content = new object[]
{
     this.transform.position,
     this.transform.rotation,
};

RaiseEventOptions raiseEventOptions = new RaiseEventOptions
{
      Receivers = ReceiverGroup.All
};

SendOptions sendOptions = new SendOptions { Reliability = true };
PhotonNetwork.RaiseEvent(evCode, content, raiseEventOptions, sendOptions);


With this RaiseEvent, I'm trying to send to all players including MasterClient, powerUpTiles position, but it seems that it's not working. PC is having them in a different order than mobile. I'm thinking the problem is that my powerUps parent are not PhotonView components but I'm thinking that the world position of powerUp tiles should be sent for all players and parents shouldn't be network components. I'm new to PUN and I'm still learning. Which is the best approach for what I'm trying to achieve?

Comments

  • DragosA
    DragosA
    edited March 2020
    Options
    Update: I'm trying to PhotonNetwork.RaiseEvent() after a scene was loaded but it seems that the eventCode from OnEvent callback is 253. How I can skip that code and RaiseEvent with my custom byte code, or maybe how can I RaiseEvent after scene was loaded?
  • Tobias
    Options
    You set the eventCode in RaiseEvent (first parameter).
    On the receiving side, the OnEvent method gets an object with .Code, as defined by you.