Applying the Energy Bar to the player prefab

At the end of this, I applied all my prefabs - and found that my Player Prefab had the energybar raw-image empty.

I tried multiple times - and found that while I can select it from my player in the scene game - it keeps clearing it from the prefab and will not let me re-apply it.

When I try changing the player prefab to add it directly - I cannot add the energy bar prefab to it.(NB I called it a Stamina bar instead)…:

The screenshot shows me selecting the empty Image on the right, the popped up options in the middle (ie none) and on the left, the prefab for the UI showing the stamina bar that i CAN select only on the instance of the player, not the prefab.

Any ideas?

Hi Brian,

Sorry if this was one of the topics you were hoping to have had a response on by now.

If you expand your Assets through the Project view, where exactly is the image file which you are trying to use, it’s clearly not within the _Characters / Player directory as per your screenshot.

Hi Rob,

I’ll try to put out as much info as I can. The script is looking for a raw image:

public class Stamina : MonoBehaviour
{
    [SerializeField] RawImage staminaBarImage;
    [SerializeField] float maxStamina = 100f;
    [SerializeField] float recovPerSecond = 5f;

The player instance in the scene is happily linked to the stamina bar shown in the top-left:

But if I go to the prefab for that GameCanvas - I cannot link it to the Player prefab:

Actually, I just did…link it… :blush: I think you just played the part of my Rubber Duck!

1 Like

“Quack!” :wink:

Ducky

So - all solved now?

Yep, thanks… It’s one of those things where It’s the obvious thing that I was sure I tried it originally… ie. just dragging prefab to prefab…

1 Like

Glad to hear you’re all sorted and can more forward again Brian.

If you have a corresponding post in the Q&A on Udemy, if you could perhaps mark it as solved it will help when the team are working through - perhaps include your solution also in case any other students have the same issue. :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms