Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Default references will only be applied in edit mode / Assining Text

Discussion in 'Editor & General Support' started by pauljbonte, Nov 11, 2017.

  1. pauljbonte

    pauljbonte

    Joined:
    Nov 11, 2017
    Posts:
    12
    Hey there, I was currently doing the Roll A Ball Tutorial in Unity. I was watching Video 7 of 8. When he assigns the Text into the right field in the inspector of the Script it works. For me, it says: Default references will only be applied in edit mode. I basically just want to assign the Unity UI Text to the right field from a script.
    I am getting this error:
    NullReferenceException: Object reference not set to an instance of an object
    PlayerController.SetCountText () (at Assets/Skripts/PlayerController.cs:44)
    PlayerController.Start () (at Assets/Skripts/PlayerController.cs:18)


    What could be the error?

    Thank you for your help!
    Paul
     
  2. Chailotl

    Chailotl

    Joined:
    Apr 11, 2017
    Posts:
    44
    Sounds like you're currently in play mode; you'll want to press the play button at the top so that it's depressed and return back to edit mode so that you can set the default in the inspector.

    Remember, any changes in play mode are not saved!

    The null reference you're getting is probably because you're not setting the default in the inspector :p
     
  3. pauljbonte

    pauljbonte

    Joined:
    Nov 11, 2017
    Posts:
    12
    I´m not in play mode, and the play button is black.
     
  4. Chailotl

    Chailotl

    Joined:
    Apr 11, 2017
    Posts:
    44
    Yeah you're definitely in play mode, even if you're not in game view currently.
     
  5. pauljbonte

    pauljbonte

    Joined:
    Nov 11, 2017
    Posts:
    12
    But how can I exit play mode, when I´m not in play mode?
     
  6. Chailotl

    Chailotl

    Joined:
    Apr 11, 2017
    Posts:
    44
    Try clicking the play button...?
    If your play button looks like this:

    I can assure you that you are most definitely in play mode.

    Just press the play button so that it is not dark anymore, and switch back to scene view.
     
  7. pauljbonte

    pauljbonte

    Joined:
    Nov 11, 2017
    Posts:
    12
    I swear I´m not stupid. It´s still not working. As you can see, the button is blue, I´m in scene view and it´s still not working!
     

    Attached Files:

  8. Chailotl

    Chailotl

    Joined:
    Apr 11, 2017
    Posts:
    44
    @pauljbonte
    ...Your play button is dark/pressed, silly =w=

    Being in scene view doesn't mean you're not in play mode. The two are not mutual exclusive, so you can switch to scene view while in play mode, and switch to game view while in edit mode.
     
  9. pauljbonte

    pauljbonte

    Joined:
    Nov 11, 2017
    Posts:
    12
    Now I´m not in play mode. Same problem...
     
  10. pauljbonte

    pauljbonte

    Joined:
    Nov 11, 2017
    Posts:
    12
    :(
     

    Attached Files:

  11. Chailotl

    Chailotl

    Joined:
    Apr 11, 2017
    Posts:
    44
    The console errors don't get cleared when exiting play mode. (Though they can be set to clear when pressing play)

    So now try dragging the text to the right field in the inspector and press play. This time it should work with no null exception errors.
     
  12. pauljbonte

    pauljbonte

    Joined:
    Nov 11, 2017
    Posts:
    12
    It wont let me drag it into the right field.
     
  13. Chailotl

    Chailotl

    Joined:
    Apr 11, 2017
    Posts:
    44
    Doesn't make sense; could you provide more details, please?
     
  14. pauljbonte

    pauljbonte

    Joined:
    Nov 11, 2017
    Posts:
    12
    The mouse turns into a crossed out circle.
     
  15. Chailotl

    Chailotl

    Joined:
    Apr 11, 2017
    Posts:
    44
    I know that, what I'm saying is that unless something freaky is happening, it won't let you drag a component to a field because they are mismatched. (e.g. can't put a texture component in a transform field)
     
  16. pauljbonte

    pauljbonte

    Joined:
    Nov 11, 2017
    Posts:
    12
    I think that is, because I´m apparently still in play mode (=not in edit mode)
    But I´m not in play mode.
     
  17. Chailotl

    Chailotl

    Joined:
    Apr 11, 2017
    Posts:
    44
    Have you tried restarting Unity yet?
     
  18. pauljbonte

    pauljbonte

    Joined:
    Nov 11, 2017
    Posts:
    12
    Yes. Should I just send you all the files and you can try to fix it?
     
  19. Chailotl

    Chailotl

    Joined:
    Apr 11, 2017
    Posts:
    44
    I'm on my phone until late evening, so if you do you'll have to wait ^^;
     
  20. pauljbonte

    pauljbonte

    Joined:
    Nov 11, 2017
    Posts:
    12
    How should I send the files?
     
  21. pauljbonte

    pauljbonte

    Joined:
    Nov 11, 2017
    Posts:
    12
    I don´t know how to send it!
     
  22. Chailotl

    Chailotl

    Joined:
    Apr 11, 2017
    Posts:
    44
    Sorry, been busy lately; why don't you use some sort of file upload service? There's ones like Mediafire, or even OneDrive or Google Drive. (Dropbox is blegh)
     
  23. esteve_soler

    esteve_soler

    Joined:
    Jan 3, 2018
    Posts:
    1
    I have the same problem. "Default references will only be applied in edit mode"

    I tried restarting Unity, restarting PC without success.

    Can anyone Paul or Rausy explain how you solve it.

    Thanks in advance.
     
  24. escape0707

    escape0707

    Joined:
    Nov 4, 2017
    Posts:
    1
    Are you guys trying to apply a ref to "A Script" or "A Prefab"?
    Notice in the video, he apply the ref to his prefab.
     
  25. boctulus

    boctulus

    Joined:
    May 4, 2018
    Posts:
    1
    Same problem here
     
  26. seyeswince

    seyeswince

    Joined:
    Jul 5, 2017
    Posts:
    2
  27. scottaswenson

    scottaswenson

    Joined:
    May 15, 2019
    Posts:
    1
    For anyone who bumps into this, your error is likely to be that both the script object and the player object show this field, but only the player object will accept a dropped value. So you must set your inspector to the player object before dragging your text object!
    The same thing is true of the earlier drag of the player object to the camera object: rather than trying to drag it to the controller script, choose the camera in the inspector first.
     
    katief650 and marc_unity692 like this.
  28. FalsAlarm

    FalsAlarm

    Joined:
    Dec 12, 2016
    Posts:
    21
    I have had this problem with Unity 2019 and I couldn't figure it out until I found this thread. It appears that the script object when you click on the script in the Assets, shows the field and so does the object in the hierarchy that you have the script attached to. The script file in the assets folder will not be able to accept the Text into the field. But if you click on the object in the hierarchy where the script is attached to(the instance), it attaches and works just fine. :)