Home > Net >  Null Reference Exception in Canvas
Null Reference Exception in Canvas

Time:08-21

this should be relatively straightforward but i cant figure out what is going wrong. I have a canvas and background image as a child of that canvas. When i add a text child that is a sibling of the background image, it allows me to do so. but when i edit any of the fields it gives me a null reference exception.

Here is the error message in full:

NullReferenceException: Object reference not set to an instance of an object
UnityEditor.PropertyEditor.DrawEditors (UnityEditor.Editor[] editors) (at /Users.   
/bokken/buildslave/unity/build/Editor/Mono/Inspector/PropertyEditor.cs:1550)
UnityEditor.PropertyEditor.RebuildContentsContainers () (at /Users/bokken/buildslave.   
/unity/build/Editor/Mono/Inspector/PropertyEditor.cs:804)
UnityEditor.InspectorWindow.RedrawFromNative () (at /Users/bokken/buildslave/unity.       
/build/Editor/Mono/Inspector/InspectorWindow.cs:144)

CodePudding user response:

This is because the object that you're trying to access is null.

This may happen if a script runs before another one or if you've failed to assign a value to the variable.

Go Edit->Project Settings->Script Execution Order to say which order your scripts should run.

Also, ensure that you are either assigning a variable on Start or in the inspector then add a null check before accessing your variable.

Without looking at your script and hierarchy it is impossible to say where your exact error is but you can solve it easily by following the exceptions and intelli-sence recommendations.

  • Related