Pull a RawImage from Resources

Hey everyone,

I’ve got these UI icons that are RawImages that i use for skills and do a bunch of things with for example: setting alpha low when it’s on cooldown and gradually increasing it as the skill recharges.

It was going fine until i needed to make my system more dynamic because the amount of skills is getting bigger and bigger and now i need to fill the icons with the right icon and i’d like to do that using Resources.Load because it’s simple and i’m also using it for the SFX.

void Awake() {
    //Check Selected Skills
    module1 = PlayerPrefs.GetString("Module1");
    Debug.Log(module1);
    //Icons
    Module1 = GameObject.Find("Module1");
    Debug.Log(Module1);
    modIcon1 = Module1.GetComponent<RawImage>();
    Debug.Log(modIcon1);
    //Fill Icons with the right Image
    RawImage raw = Resources.Load<RawImage>("Icon/" + module1);
    modIcon1 = raw;
    Debug.Log(raw);

No errors and only raw returns null so I’m guessing this doesn’t work because you can’t set texture type as RawImage in Editor so i’m looking for a work-around or solution that hopefully doesn’t require me to change all the other code.

You don’t want to load the RawImage. You want to load the texture, and set it to the variable on your RawImage.

RawImage is a UI element. Texture2D is the file in your resources folder.

So:

modIcon1.texture = Resources.Load<Texture2D>("Icon/"+module1);