Illegal view id issues occuring randomly

Hi. Im having issues with my npc's that are "not" instantiated and would be very hard to transition to an instantiated state. The problem however lies with the view id dissapearing randomly before building f.e when i override a prefab i have to reopen the scene or else it gets stuck as view id 0.

Im getting close to launch and im stressed to push a version with broken ids

I tried writing scripts that stop the build if invalid photon view id but when the app is not running it always returns a zero

Any ideas?


  • ViewIDs on prefabs should be 0.

    If you got objects with PhotonViews in the scene, those should get a unique number > 0 each.

    I didn't really get what happens in your case.

  • So what is happening is if i save prefabs from scene, the scene objects (in this instance my npcs) loose their view id's and if i build without reentering the scene they get a view id = 0 in the built product. What could help me a lot would be to stop build if anything in scene has view id = 0 but i have not been successful in doing that

  • Tobias
    Tobias admin

    Which PUN 2 version do you use and which Unity version?

    Is the build done via a build server or locally from someone's Unity Editor?

  • Locally here is how to reproduce.

    1.Add prefab into scene

    2.Change prefab, override prefab settings (overrides, apply all) and build right away without reentering scene

    This results in the prefab having id of 0 once its built.

    Im guessing the id reassignment does not mark the object dirty and this does not ask player to save the scene?

  • Hmmm, ok. Yes, I can imagine that could be a problem. If Unity overrides some values for the scene objects, it might apply 0 to the ViewID, which is the needed value in the Prefab. PUN can only apply ViewIDs in scenes that are open...

    I don't have a good solution for this at the moment. We'd probably have to open all scenes and assign ViewIDs where necessary. Or .. keep it 0 until loaded, then apply an ID. I don't know if this can be done in a deterministic way however, as order of loading scenes could be different per client and even within the same scene, I couldn't say if finding the ViewIDs has a deterministic order on all platforms.

    Right now, I can only suggest to re-open the scenes or avoid overriding this value (don't know if Unity has some attribute to avoid it).

  • Ill do that!

    could this not be fixed by marking object dirty when the id is assigned (im asking genuinely i have no idea)

  • btw this is just an issue for me as i have around 70 scenes each containing an island and occasionally we find random npc completely broken

  • could this not be fixed by marking object dirty when the id is assigned (im asking genuinely i have no idea)

    I actually don't know either. The way I imagine the problem happens, saving the prefab will overwrite the value in the scene-objects. If that's the case, I don't know we could somehow tell Unity to always keep the value which is scene specific.

    btw this is just an issue for me as i have around 70 scenes each containing an island and occasionally we find random npc completely broken

    Oh, dang. Yes, I can see how that's annoying. I am sorry I can't provide a solution right away.

    You could possibly keep an eye on the scene files. If they are text format, you should see when they changed. If they change after editing a prefab, then look into what changed. If you find some "viewID" field that gets 0 assigned (and had a non-zero value earlier). This is what we want to avoid.

  • am i looking for the sceneViewID?

    that's the only "ViewID" im seeing in the file

  • Yes.

  • Last question.

    Any ideas if and how i could run through all scene objects and check their id and cast an error if i find a 0 to stop the build. I gotten something similar but when prefabs for example are checked (which always have a 0 ofcource) it breaks the whole process

  • You would need to open all scenes, I guess. Unless you check Unity's yaml directly.

    If you open each scene in Unity, this may affect the viewIDs and other values, I guess. But in general, you should be able to create a script that does it and you could run this as a pre-build step via commandline maybe.

    Sorry. I don't know enough about Unity's build options as I don't need them in daily life.

    Would be interested to know what you come up with or find, however.

  • Ill let you know how it goes im going to try and do this next weekend

  • Introfernal
    edited April 4

    Okay so i have the system setup but i dont actually see a "propertyPath: sceneViewId value: 0" any where in the scene file when it's set to 0, only valid view id's (lol shouldve checked before coding),

  • Tobias
    Tobias admin

    Which means .. case closed or at which point are you now?

  • Im close but i cant find any sceneviewid as 0 in the scene files even though they are set to 0 when running :(

  • They should be non-zero when the scene gets saved. At runtime, they should not change.

    Maybe you build with a build server and it changes the scene view IDs? We had this issue in some cases. It might make sense to remove the PhotonEditor code in that case (or at least add conditions for compilation that make it only run in Editor sessions, not in Cloud build).

  • Introfernal
    edited April 23

    Alright so ive tried multiple times but im stuck because when the id is 0 in the scene file it's just not present at all. the section is empty in the scene text files. Im probably just going to make a huge checklist for each update of my game to bypass this.

    i dont build with build server btw

  • Is there any way to tell Unity never to overwrite some value which was specified on a scene-object, even if the prefab updates?

    using System.Collections;
    using System.Collections.Generic;
    using Photon.Pun;
    using UnityEditor;
    using UnityEditor.Build;
    using UnityEditor.Build.Reporting;
    using UnityEditor.SceneManagement;
    using UnityEngine;
    using UnityEngine.SceneManagement;
    public class BuildPreprocessing : IPreprocessBuildWithReport
        public int callbackOrder { get { return 0; } }
        public void OnPreprocessBuild(BuildReport report)
        public static void ValidateBuildEveryScene()
            string mainMenuScenePath = "Assets/Scenes/MainMenu.unity"; // Replace with your own path
            string[] scenePaths = new string[EditorBuildSettings.scenes.Length];
            for (int i = 0; i < EditorBuildSettings.scenes.Length; i++)
                scenePaths[i] = EditorBuildSettings.scenes[i].path;
            foreach (string scenePath in scenePaths)
                Scene scene = EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Additive);
                Debug.Log($"Opened scene '{}'");
            UnityEngine.Object[] views = UnityEngine.Object.FindObjectsOfType(typeof(PhotonView));
            foreach (var o in views)
                var view = (PhotonView)o;
                if(view.sceneViewId <= 0) Debug.LogError("ViewID is 0 or less on " + + view.sceneViewId);
    This is how i solved it :)