Home c# nullreferenceException when searching using GameObject.find

nullreferenceException when searching using GameObject.find




created a button that clicks the window (Delete) panel. Bottom script.

using system.collections;
Using System.Collections.Genic;
using unityengine;
Public Class Actions: Monobehaviour
  Public Void Delete ()
    // int ID = GameObject.Transform.Parent.getcomponent & lt; ID & GT; (). ID;
    GameObject Deletewindow = GameObject.find ("Window (Delete)");
    Print (Deletewindow);
    //Deletewindow.getcomponent<delete> ;().id = id;

To my surprise, the result is returned empty and because of this pops error

NULLReferenceException: Object Reference Not Set to An Instance of An Object

Screenshot here and below.

Such errors began to meet with me often.
Finally someone tell me – where is my mistake?

Answer 1, Authority 100%

GameObject.find Lookages only active objects. And you have this panel, judging by the screen, turned off.

Try search with Resources.findObjectSoftypeall . It seems like inactive objects will also return.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions