UnityEngine.UI.Graphic.OnRebuildRequested errors

Does anyone knows what this means?

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)

It appears on Play and on saving scene.

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);*
    
  •  var expanded = new int[0];*
    
  •  while (prop.Next(expanded)) {*
    
  •  	yield return prop.pptrValue as GameObject;*
    
  •  }*
    
  • }*
    }

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.

All the best

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.

For me it was a missing script that was causing this exception.

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)…

To fix –

  • Select object to which script has assigned
  • Re-assign script by drag drop in Inspector
  • Save project

You did it :slight_smile:

Check Hierarchy GameObject , Some one missing script

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…

try
{		
	blah blah...
}
catch(UnauthorizedAccessException ex)
{
	//Debug.Log (ex);
}

Because I wasn’t doing anything with ex, unity decided to give me this cryptic error o.O

Annoyingly it’s not the first time I’ve run into that one but it still took me 30 mins to realise what I’d done.

EDIT: To clarify, it was only this part of the OP’s error I was seeing…

UnityEngine.UI.Graphic.OnRebuildRequested () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Graphic.cs:399)

But searching for that led me here.