Skip to content

UnassignedReferenceException when Child objects have components with unassigned Transform #20

@gw1108

Description

@gw1108

To recreate this open up Giles and make a .cs script like this:

public class DummyInspector : MonoBehaviour { public Transform DummyTransform; }

Create a prefab that is an empty parent object with a child object. The child object must have the DummyInspector.cs component.

Drag the parent object into Resources/LevelEditorPrefabs to create a prefab. If you try to save a Giles level with this object instantiated it'll throw a UnassignedReferenceException. Full stack trace would be something like this:

UnityEngine.UnassignedReferenceException: The variable theTransform of DummyTransform has not been assigned. You probably need to assign the theTransform variable of the DummyTransform script in the inspector. at (wrapper managed-to-native) UnityEngine.Transform:get_childCount () at UnityEngine.Transform+Enumerator.MoveNext () [0x00007] in C:\buildslave\unity\build\artifacts\generated\common\runtime\TransformBindings.gen.cs:448 at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList (Newtonsoft.Json.JsonWriter writer, IEnumerable values, Newtonsoft.Json.Serialization.JsonArrayContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract collectionContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x00108] in C:\Users\George\Downloads\Json.Net.Unity3D-master\Json.Net.Unity3D-master\src\Newtonsoft.Json\Serialization\JsonSerializerInternalWriter.cs:684 at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonContract valueContract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x000fe] in C:\Users\George\Downloads\Json.Net.Unity3D-master\Json.Net.Unity3D-master\src\Newtonsoft.Json\Serialization\JsonSerializerInternalWriter.cs:179 at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeDictionary (Newtonsoft.Json.JsonWriter writer, IDictionary values, Newtonsoft.Json.Serialization.JsonDictionaryContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract collectionContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x00176] in C:\Users\George\Downloads\Json.Net.Unity3D-master\Json.Net.Unity3D-master\src\Newtonsoft.Json\Serialization\JsonSerializerInternalWriter.cs:1091 UnityEngine.Debug:LogError(Object) GILES.pb_Scene:SaveLevel() (at Assets/Lib Assets/GILES/Code/Scripts/pb_Scene.cs:151) GILES.pb_SaveSceneButton:Save(String) (at Assets/Lib Assets/GILES/Code/Scripts/GUI/Toolbar/pb_SaveSceneButton.cs:61) GILES.pb_SaveSceneButton:OnSave(String) (at Assets/Lib Assets/GILES/Code/Scripts/GUI/Toolbar/pb_SaveSceneButton.cs:35) GILES.Interface.pb_FileDialog:Save() (at Assets/Lib Assets/GILES/Code/Scripts/GUI/pb_FileDialog.cs:266) UnityEngine.EventSystems.EventSystem:Update()

When json is trying to serialize all the components it tries to serialize Transform/GameObject references that might be public in the inspector. Even though the values are null JSON evaluates them as not null.

Also, if you make the Child object a prefab then create a new Parent/Child prefab with the first prefab you won't get this error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions