Is it just me or is unet just completely buggy and broken everywhere?? If you’ve been following my recent issues you’ll notice I’m having all sorts of trouble - I am new to unet so it could just be me however I have been writing software for 20+ years and this just seems nuts.
Anyway… I have a prefab that i’ve been using for a while now but deleted them all from my scene recently until today I thought I would add one back in and hit this error in the editor:
NullReferenceException: Object reference not set to an instance of an object
UnityEditor.Networking.NetworkTransformPreview.OnPreviewGUI (Rect r, UnityEngine.GUIStyle background) (at Unity-Technologies-networking-40b219054a68-v5.5/Editor/NetworkTransformPreview.cs:55)
UnityEditor.ObjectPreview.OnInteractivePreviewGUI (Rect r, UnityEngine.GUIStyle background) (at C:/buildslave/unity/build/Editor/Mono/Inspector/Editor.cs:113)
UnityEditor.ObjectPreview.DrawPreview (IPreviewable defaultPreview, Rect previewArea, UnityEngine.Object[] targets) (at C:/buildslave/unity/build/Editor/Mono/Inspector/Editor.cs:225)
UnityEditor.ObjectPreview.DrawPreview (Rect previewArea) (at C:/buildslave/unity/build/Editor/Mono/Inspector/Editor.cs:128)
UnityEditor.PreviewWindow.OnGUI () (at C:/buildslave/unity/build/Editor/Mono/Inspector/PreviewWindow.cs:98)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Since I’ve been going through the unet code I thought I would take a look and this is the line in question:
float angleDiff3D = Quaternion.Angle(m_Transform.rigidbody3D.rotation, m_Transform.targetSyncRotation3D);
Just before it is the condition
if (m_Rigidbody3D != null) however this variable is never actually used, as you can see its using m_Transform.rigidbody3D instead. From an earlier bug(?) I found in the NetworkTransform there are cases were Awake() is not called and the NetworkTransform.rigidbody3D will return null in these cases as it is doing here.
m_Rigidbody3D and m_Rigidbody2D are never used anywhere in this code. The fix to the above problem is to consistently use either the m_Transform rigid bodies or the m_Rigidbody variables but not to mix them.
But back to the root cause, why is Awake not getting called on these NetworkTransform objects to being with?