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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
public class UIFade : MonoBehaviour
{
public Image fadeScreen;
private bool shouldFadeToBlack;
private bool shouldFadeFromBlack;
public int test;
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.
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.
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.