Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Bug Weird Photon Pun 2 OnControllerChange issue

Discussion in 'Multiplayer' started by marcospgp, Mar 24, 2021.

  1. marcospgp

    marcospgp

    Joined:
    Jun 11, 2018
    Posts:
    153
    I have 3 zombie prefabs in the scene that have some initialization code in OnControllerChange.

    The thing is there is always one of these zombies whose OnControllerChange does not get triggered when I create a room and join it.

    These zombies have prefab overrides all the time although no actual change has happened - it seems to simply detect that the photon view ID has changed.

    The thing is that the zombie whose OnControllerChange does not get triggered is always the last one on whose overrides I clicked "apply all".

    This is a really weird issue and I have no idea what else it could be. Does anyone have any suggestions?
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,957
    Do you use the latest PUN 2 version? If not: Try to repro in v2.29.

    Yes, the viewID is pretty much always an override over the prefabs (in a scene). All objects need their own ID. There is no way a prefab would not store it, too.
    When you load the objects with the scene, you could trigger the initialization with Start(), too. There is not necessarily a controller change but all objects get loaded and started.
     
  3. marcospgp

    marcospgp

    Joined:
    Jun 11, 2018
    Posts:
    153
    Thanks for the response! I no longer have the setup I did when I noticed this issue, but I just updated the PUN 2 package and will create a new thread if I notice any issues.

    I think I can't use Start() for objects that are in the scene before joining a room, right? Because when it gets called PhotonView.IsMine will be set to false (though I suppose it should be true since the player isn't connected to a room so they own everything)
     
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,957
    The state of a PhotonView is only valid once the client is in a room. The IsMine will default to true but there is no Owner or Controller, as long as the client is not in a room yet.
     
    marcospgp likes this.