Home > Blockchain >  Why cant I drag and drop a Sprite in a Scriptable Objects inspector? [SOLVED]
Why cant I drag and drop a Sprite in a Scriptable Objects inspector? [SOLVED]

Time:03-17

So I have a scriptable object that holds a public Image variable. And I want to drag an image to the inspector, but I'm not able to get it to work. I have changed the Texture Type to Sprite (2D and UI). I have tried to find people with similar problems but the only answer I can find is to change the Texture Type to sprite. And I need the Texture Type to be used for UI for ex Player HUD that shows cooldown on abilities.

Edit: Solved by making a prefab of the image I wanted to drag and drop.

Picture of Image Inspector

Picture of Scriptable object inspector

CodePudding user response:

Use "Texture" or "Sprite" instead of "Image" as type of "abilityIcon" in "FireBall.cs".

CodePudding user response:

Image is a class inherited from UnityEngine.UI namespace. And to be shown requires a Canvas component.

You can create a prefab with an Image that contains your sprite in order to add to your scriptable object, then use abiltyIcon.sprite in order to recieve the original sprite when needed.


If you don't want to create a prefab then the solution would be using Sprite class as mentioned.

Just by doing the reverse path I've mentioned early. Instead of having an Image with a Sprite you would have a Sprite and add it to an empty Image on the code.

Considering you are using a scriptable object, check if this solution isn't better than the first one.

  • Related