Possible to set viewID at runtime?

I have a scene object from the first scene that persists throughout the game and has a viewID of 1. When I place prefabs in other scenes, Photon always autoassigns conflicting viewIDs because it doesn't know about the view in the original scene. What I would like is to have the viewID set at runtime or have the option to allocate it manually via script.

Even if I attempt to allocate the viewID in Awake(), it still conflicts and generates an error. I'm finding that I have to manually set the viewIDs of all my scene objects to ensure no conflicts which is not ideal.

Is there any way to assign viewIDs at runtime for scene objects so you don't have to manually assign them?

Comments

  • Found this at the top of Google - what was the answer to this?
  • I don't think I ever got an answer on this so I just set my viewIds to really high numbers for scene objects and Photon seems to start with low ids so it works out. I think 999 is the highest viewID you can use so I start there and work my way down for static objects.
  • JohnTubeJohnTube mod
    edited October 23
    Hi @strangegames,

    Thank you for choosing Photon and sorry for not answering here earlier.

    I don't think I ever got an answer on this
    You could always send an email if you do not get a reply within 2 business days.

    What PUN version do you use?
    I know @xblade724 uses PUN Classic.

    When I place prefabs in other scenes, Photon always autoassigns conflicting viewIDs because it doesn't know about the view in the original scene.
    This looks like a bug that we need to fix first if you could help us with minimal repro steps.

    Did you read the important note here or the recommended way of switching scenes.

    I think 999 is the highest viewID you can use so I start there and work my way down for static objects.
    This depends on MAX_VIEW_IDS. Read about it here.

    so I just set my viewIds to really high numbers for scene objects and Photon seems to start with low ids so it works out.
    I did not get the workaround, could you be more specific?

    @xblade724 I guess you want an answer to the question in the title "Possible to set viewID at runtime?", right? May I know why do you need this? Is it also for scene objects? Do you instantiate those objects at runtime or do you have them in the scene already?

    In any case, there is PhotonNetwork.AllocateViewID(PhotonView) and PhotonNetwork.AllocateSceneViewID(PhotonView).
  • xblade724xblade724
    edited November 3
    I think a better wording for my goal would be: How to *automatically have Photon choose* the viewId? My issue is the same as this one:

    > When I place prefabs in other scenes, Photon always autoassigns conflicting viewIDs because it doesn't know about the view in the original scene.


    So in 1 scene, I'll start at 0. 2nd scene, I'll start at 100. Other scene, I'll start at 300. Or go backwards from 999 at the farthest-end scene. It's not necessarily ideal - I first ran into an issue with our gameover screen photonView Id's conflicting with our Id from our lobby scene. So both had the same view.

    I noticed that when PhotonViews are stored in a prefab, it'll automatically assign. However, if not in a prefab, I'd like the same feature where I can checkbox an "auto-assign" option to prevent conflicts for when I don't track a static ID. This way, I don't have to remember what IDs the other ones are in different scenes.
  • Hi @xblade724,

    In PUN2, we have addressed this issue lately.
    We have added a PunSceneSettings ScriptableObject to configure the minimal PhotonViewID per scene.
    We have a § talking about this here.

    So I guess, it's another reason to switch to PUN2.
Sign In or Register to comment.