NullReferenceException PhotonViewInspector.OnInspectorGUI

Hi, this is just a minor problem, just a bit annoying.

Whenever I drag a specific prefab from the Prefab folder in the scene I get the following error:
NullReferenceException: Object reference not set to an instance of an object
PhotonViewInspector.OnInspectorGUI () (at Assets/Photon Unity Networking/Editor/PhotonNetwork/PhotonViewInspector.cs:95)
UnityEditor.InspectorWindow.DrawEditors (Boolean isRepaintEvent, UnityEditor.Editor[] editors, Boolean eyeDropperDirty) (at C:/BuildAgent/work/300357e52574df36/Editor/Mono/Inspector/InspectorWindow.cs:888)
UnityEditor.InspectorWindow.OnGUI () (at C:/BuildAgent/work/300357e52574df36/Editor/Mono/Inspector/InspectorWindow.cs:243)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture)

It only happens on specific prefabs and only in the editor. The prefab is shown perfectly but when I drag into the scene the PhotonView component is not rendered as this error prevents the GUI code from running.

If I break the prefab connection by deleting a child from the prefab then the error disappears. I tried removing all the other components for potential conflicts but that didn't solve it.

Unity 3.5.2f2, PUN 1.15 and Photon Cloud.

Comments

  • Thanks for the heads up.
    It only happens on "specific" prefabs? Any idea what makes them special and cause this?
  • I didn't have time to further investigate on this issue but it seems:

    PrefabUtility.GetPrefabObject(mp.gameObject) as GameObject -> returns null (!) when the prefab is dragged into the scene
    EditorUtility.GetPrefabParent(mp.gameObject) as GameObject -> works fine when the prefab is dragged into the scene, also I get "PUN: Corrected one or more scene-PhotonViews."

    So far we are using the obsolete version and it seems to work fine.

    Unity 3.5.2f2
  • Is the prefab in a Resources folder?
  • Yes, it is.
  • Found the cause:
    3.5 uses PrefabUtility.GetPrefabObject
    3.4 uses EditorUtility.GetPrefabParent

    Changing to PrefabUtility.GetPrefabParent fixes the null issue and works as expected (as far as I can say).
    Thanks for pointing this out. Will be fixed in PUN v1.16.
  • Great, thanks for the info