Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnassignedReferenceException when Child objects have components with unassigned Transform #20

Open
gw1108 opened this issue Mar 11, 2017 · 1 comment

Comments

@gw1108
Copy link

gw1108 commented Mar 11, 2017

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.

@gw1108
Copy link
Author

gw1108 commented Mar 11, 2017

I found a workaround by excluding the Transform and GameObject types in pb_Reflection.cs. Line 112 add a new condition for typeof(Transform) and typeof(GameObject).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant