Search Unity

Can't create Slider or Gameobject in script

Discussion in 'Scripting' started by Brylle, Sep 4, 2020.

  1. Brylle

    Brylle

    Joined:
    Sep 4, 2020
    Posts:
    5
    So, I think I've found a legitimate bug in Unity.

    Basically, I'm trying to do something exceedingly simple, create a Slider variable or Gameobject in a script (it is a pretty extensive script).

    However, every time I create either variable, it does not appear in the inspector such that I can assign the slider (or Gameobject) to it.

    Code looks like:

    public Slider slide;
    public Gameobject Obj;

    I think I've found an honest to goodness bug, let me know if anyone thinks otherwise?
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    Are you using this:
    Code (CSharp):
    1. using UnityEngine.UI;
    or this:
    Code (CSharp):
    1. using UnityEngine.UIElements;
    If it's the second one, that your problem. It should be the first one.

    Beyond that, do you have any compile errors?
     
  3. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    Have you looked in the console for error messages?
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689
    If you see no errors, check the upper right corner of the console window to ensure your errors are toggled on.

    If there really are no errors, right-click the script file in the Project panel and reimport. Sometimes Unity fails to notice code changes, or gets wedged in some weird state where it thinks there's nothing to compile.
     
  5. Brylle

    Brylle

    Joined:
    Sep 4, 2020
    Posts:
    5
    Yeah, that is up top, it even unfades because that is now being utilized after I enter the code. The funny thing is no compile errors, it runs, it even detects an error if I enter the same variable twice (meaning entering Slider Slide twice or something, so it sees it, but its just not showing up in inspector).
     
  6. Brylle

    Brylle

    Joined:
    Sep 4, 2020
    Posts:
    5
    Yes, it actually runs with no errors, it just doesn't show up in inspector (making it useless or impractical).
     
  7. Brylle

    Brylle

    Joined:
    Sep 4, 2020
    Posts:
    5
    Yes, it is detecting errors, they clear on run (they are just warnings from other scripts, but nothing related to this I believe, actually, now that you mention it I will go look over all the warnings to see if any could be related). Darn, I already cleared them but when I run it some more and I see the warnings repost I'll see if any are related (its not unusual to have a lot of warnings for me, but they tend to not stop the game from running, but next time they pile up I'll check them to see if that could be a solution). Thank you all btw for your suggestions so far, I'll let you know if the warnings pan anything out.
     
  8. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    To be clear, you are using UnityEngine.UI?

    Any chance you could share the whole script here? (Please use the Code button in the text editor so it stays nicely formatted)
     
    Brylle likes this.
  9. Brylle

    Brylle

    Joined:
    Sep 4, 2020
    Posts:
    5
    I'm an idiot! IT WAS using the second one (I remembered wrong and went to double check), used UnityEngine.UI and bam, right up.

    HA! I feel so stupid! I've been using Unity for literally (on and off) for like 10 years? NEVER asked a question, just a major lurker feeding off the advice of others. Well, today that all changed! Thank you (all of you), I really apricate it!
     
    Kurt-Dekker and PraetorBlue like this.
  10. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689
    Glad you're up and running. This sorta thing happens from time to time, for a variety of reasons: another namespace or class will suddenly be the (technically correct) thing the compiler latches onto and nothing you do can seem to make it work.

    My favorite one is when you are trying to make a script to control a
    UnityEngine.UI.Slider
    , so naturally you make your Monobehavior class named
    Slider
    ... and then spend 2 hours scratching your head why NOTHING seems to work properly now. Been there, done that.