NullReferenceException: Object reference not set to an instance of an object
UnityEngine.UI.InputField.set_text (System.String value) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/InputField.cs:273)
AdvancedUser.Update () (at Assets/code/leveleditor/AdvancedUser.cs:54)
Yes, triggerParam6 is a string, it exists, and it’s inside a struct (levObjectData). Welp. No idea how to get past that.
I am on the verge of reporting it, but I don’t know if it is a known issue (no reason to report it then) and if there is any workaround to make it work.
Take out this.gameObject.. That’s a bit redundant. Probably won’t fix your problem though. Can we know a bit more about the script? Is it a base class? Is the class static? What are you trying to do? Is the script component properly setup on the game object. Also it is possible that levObjData is null so check that.
Ya either InputField is not set, of levObjData is null. I have a rule on GetComponent for any object that isn’t on a [RequiredComponent]. Always set it, and check if it’s null before accessing. That extra 4 seconds of typing saves me several minutes of debugging every time.
No, it’s just standard MonoBehaviour. If you mean levObjData, that’s just a struct. as in “public struct”.
n/a, see above.
Trying to set inputfield’s text, duh.
100% certain of that. Also I have bunch of other input fields managed by that script that set text of other fields based on certain values and these work fine.
Nope, works fine in other cases.
Sigh. I never knew I’d have to do that, but here’s the script in its whole gloomy, TheDailyWTF-y glory: http://pastebin.com/2FnQFVan
Just for the sake of knowing that nothing is null, in your start function (or anything), do this:
if (var == null)
Debug.Log("Var is null");
Do this for every variable you have in the script. That means even the variables in the update function. (temporarily move the get component calls to the start function just to test the variables)
Never ever say “But it works fine in other cases”. Oh my goodness I can’t tell you how many times I’ve thought that and been dead wrong. Put some Debug.Log statements in there and actually check if the objects are null. I think you’ll be surprised.
You don’t get this… NRE happens in, and I quote, “UnityEngine.UI.InputField.set_text (System.String value) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/InputField.cs:273)”, therefore it is a problem with Unity’s UI code, not mine.
Go to your input field component in the inspector. Make sure all of the references there are set up correctly. Input fields rely on several Text components found on other GameObjects.
This. And if you check it and there are no obvious problems, try deleting and re-creating the element. If you duplicated it from another object, it could be wonky. I have encountered this recently where UI and anim components will behave oddly after duplicating, and recreating it solves the problems. (they weren’t getting unique GUIDs for some reason). It appears to be an editor bug, but I can repro it consistently.
Why don’t you just reference a public InputField, drag and drop or FIND the input field, then go down one line and do NameOfInputField.text = so and so. That’s what I do and IT DOES WORK.