Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

public Image not show in Inspector

Discussion in 'Scripting' started by gamer123454321, Aug 1, 2020.

  1. gamer123454321

    gamer123454321

    Joined:
    Mar 25, 2020
    Posts:
    83
    Hi! In script I tried to public different type of variable, they all show in Inspector except Image. Can Anyone Help?
     
  2. Terraya

    Terraya

    Joined:
    Mar 8, 2018
    Posts:
    646
    try to use :

    Code (CSharp):
    1. [SerializeField] public Image test;
     
  3. gamer123454321

    gamer123454321

    Joined:
    Mar 25, 2020
    Posts:
    83
    still not working either with [SerializeField] or not

    public Image test; this code work on other scripts but not work on GameManager script or the script I'm work on
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,888
    Do you have any compile errors in your console?
     
  5. gamer123454321

    gamer123454321

    Joined:
    Mar 25, 2020
    Posts:
    83
    No error. Game is playable
     
  6. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,888
    Can you share the whole script and a screenshot of the inspector?
     
    Bunny83 likes this.
  7. gamer123454321

    gamer123454321

    Joined:
    Mar 25, 2020
    Posts:
    83
    even sprite works fine
    question.png question2.png
     
  8. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,888
    Replace
    Code (CSharp):
    1. using UnityEngine.UIElements;
    with
    Code (CSharp):
    1. using UnityEngine.UI;
     
    Last edited: Aug 17, 2022
  9. gamer123454321

    gamer123454321

    Joined:
    Mar 25, 2020
    Posts:
    83
    It works. Thank yo so much!!:)
     
  10. LordVise

    LordVise

    Joined:
    Aug 1, 2020
    Posts:
    8
    Brilliant! Have been battling with this for hours. Thanks for posting the solution.
     
  11. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,912
    Hopefully it's clear what the issue was ^^. You essentially grabed your kid's toy hammer instead of the actual steel hammer and wonder why you can't drive the nail in :) Of course this is a bad analogy because I don't want to play down the Image class from the UIElements namespace. Though the point is that it's just the completely wrong image class that you're looking for. Unity has several UI systems. Have a look at this page to see a rough comparison between the different systems. Of course there are logical naming overlaps between the system. That's why we have namespaces to distinguish them. Like you may have different boxes of screws. If you grab the wrong box, you get the wrong screw ^^.
     
  12. kaplovski

    kaplovski

    Joined:
    Sep 16, 2013
    Posts:
    2
    That UnityUI does not exist in my Unity version
     
  13. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,186
    Make sure you have the Unity UI package installed.
     
  14. twannyb

    twannyb

    Joined:
    Mar 2, 2023
    Posts:
    1
    Helped me not yeet my computer out of the window, ty haha
     
  15. Frotiman

    Frotiman

    Joined:
    Feb 23, 2022
    Posts:
    2
    uhh..

    upload_2024-1-1_13-14-56.png
     
  16. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,606
    You probably have both
    using UnityEngine.UI
    and
    using UnityEngine.UIElements
    in your script, meaning your code editor can't determine which one to use.

    Either remove the
    using
    you you don't need (likely the latter), or use the namespace qualified name for your usage of Image.

    Though you could've just googled the error and come to this answer.
     
    Bunny83 likes this.