NullReferenceException: Object reference not set to an instance of an object
UnityEngine.UI.Graphic.OnRebuildRequested () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Graphic.cs:399)
UnityEngine.UI.GraphicRebuildTracker.OnRebuildRequested () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/GraphicRebuildTracker.cs:33)
UnityEngine.CanvasRenderer.RequestRefresh () (at C:/buildslave/unity/build/artifacts/generated/common/modules/CanvasRendererBindings.gen.cs:244)
Solved – indeed there was a missing script! fwiw this is how I find missing scripts in my project:
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
// from: http://wiki.unity3d.com/index.php?title=FindMissingScripts
public class FindMissingScriptsRecursively : EditorWindow
{
static int go_count = 0, components_count = 0, missing_count = 0;
[MenuItem("Window/Find Missing Scripts (All)")]
static void FindInAll()
{
go_count = 0;
components_count = 0;
missing_count = 0;
foreach (var root in SceneRoots())
{
//Debug.Log(root);
FindInGO(root);
}
Debug.Log(string.Format("Searched {0} GameObjects, {1} components, found {2} missing", go_count, components_count, missing_count));
}
static void FindInGO(GameObject g)
{
go_count++;
Component[] components = g.GetComponents<Component>();
for (int i = 0; i < components.Length; i++)
{
components_count++;
if (components *== null)*
{ missing_count++; string s = g.name; Transform t = g.transform; while (t.parent != null) { s = t.parent.name +“/”+s; t = t.parent; } Debug.Log (s + " has an empty script attached in position: " + i, g); } } // Now recurse through each child GO (if there are any): foreach (Transform childT in g.transform) { //Debug.Log("Searching " + childT.name + " " ); FindInGO(childT.gameObject); } }
static IEnumerable SceneRoots()*
{*
var prop = new HierarchyProperty(HierarchyType.GameObjects);*
Hi,
I also had that same issue. I found that a class having one name and its file having other name.
eg if " abcdefg " is the name of the class, and its file name was " uvwxyz ". I changed the class name as the file name. Then the error was cleared. Please check that.
I have removed a script from the project, but still one game object referenced to it. After removing the reference to missing script in objects inspector the problem dissapeared.
Check all your prefabs and game object in inspector for missing scripts in components.
are you on WebPlayer platform ? because at least on my computer on that platform all Unity UI elements causes this error.
don’t even have to click Play. just by using unity keeps flooding this error in console.
This is happening when you just renamed(with Rename option) your script name from MoniBehaviour, saved all scripts which are using that script reference but you forgot to re-assign reference of renamed script in Inspector(as it has been getting missed when you changed script name)…
Just wanted to add to the list of things that can cause this sort of error message. I was attempting to comment out all my Debug.Log messages and accidentally commented out one inside a catch(Exception) block…