Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

public Image from c# script dont show up in the inspector

Discussion in 'UI Toolkit' started by modulo34, Aug 2, 2020.

  1. modulo34

    modulo34

    Joined:
    Sep 13, 2014
    Posts:
    28
    I have a strange problem, when trying to add a Image from my script(just started to write it), it don't show up in the inspector, i have try to restart both Unity and VsCode, nothing happen, anyone had this problem?If a had for example ,a public int it work, never had any problem like that before


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UIElements;
    5.  
    6.  
    7. public class UIFade : MonoBehaviour
    8. {
    9.  
    10.     public Image fadeScreen;
    11.     private bool shouldFadeToBlack;
    12.     private bool shouldFadeFromBlack;
    13.     public int test;
    14.  
    dwdwdw.PNG
     
  2. JuliaP_Unity

    JuliaP_Unity

    Unity Technologies

    Joined:
    Mar 26, 2020
    Posts:
    36
    Hello, this is not the best forum area for this question unless you're making a custom inspector with UI Toolkit but I believe if you use Sprite instead of Image as the type you'll see it on the inspector and it should work as you intended it to work.
     
  3. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    4,940
    You've imported UnityEngine.UIElements, when you instead want UnityEngine.UI. Both have an Image, but the one in UI is the one that's a component that you're looking for.

    This usually happens because your editor has a popup when there's an unknown type (like "Image"), and asks you where to import it from. Depends on the editor.

    @JuliaP_Untiy, this is going to happen a lot. People will write "public Image x", and their editor will auto-suggest some namespace to import it from. I'm not sure if it's something that should be fixed (by eg. using more specific names, like ImageElement), but at least tutorials should make beginners aware that this is a thing.
     
    SimonDufour likes this.
  4. JuliaP_Unity

    JuliaP_Unity

    Unity Technologies

    Joined:
    Mar 26, 2020
    Posts:
    36
    @Baste I had missed the import, good catch! I'm bringing this discussion to the team.
     
  5. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    854
    UnityEngine.UI should not be available and therefore not suggested if the
    com.unity.ugui
    (Unity UI) package is not installed. Looking forward, once UI Toolkit becomes the default UI solution for runtime, this kind of problem should be less and less frequent.

    But it will be a pain for a while. The trade-off is that for the most part, a TextField is a TextField in all UI solutions and comes with reasonable assumptions of equivalence. We didn't want to invent new names for existing concepts, Image being one of them. At the very least, it once you have a UI Toolkit-based UI implemented, it becomes fairly easy to spot wrong types as they won't work with every other element and API.
     
    Baste likes this.
unityunity