Prefab - Can't Assign Image Field

I made a prefab from the FPSController prefab. My prefab has a script on it (on the ‘FirstPersonCharacter’ part) that has a public Image field.

On the prefab in ‘Assets’, it won’t let me assign an image, which is a 'Sprite (2D and UI). The image is also in Assets (I’m not trying to assign something from the hierarchy).

The field is defined as:

public Image interactIcon;

It shows up in the inspector, but it won’t let me assign anything to it. Is this a limitation of prefabs, and if so how would I get around it?

“Image” is a component that displays a sprite on a canvas. If you want to assign a sprite, then you need make the variable for a UnityEngine.Sprite instead.

1 Like

Ok, thanks, I see. But now I’m confused about another aspect of prefabs.

I have added a spotlight and a mesh object as children of ‘FirstPersonCharacter’ (which is child of FPSController) in the hierarchy, but when I try to make a new prefab out of it by dragging it to my prefabs folder, those child objects are not included as part of the prefab. What is it that prevents this from working? Can you only have child objects one level deep?

No, you can have as many levels as you want, you just don’t see them. But if you drag it back into the scene you’ll see they’re there.