# Cannot drag GameObject into exposed field in the Inspector

I followed the Brackeys' How to make a health bar tutorial on YouTube, and it worked perfectly when playing around with the sliders myself. But, when I tried to drag the health bar object into the script's exposed attribute in the Inspector (like Brackeys does at 10:14 in the video), but it won't let me drag it in. I followed the tutorial exactly as shown, but it still won't work. Can anyone explain why and/or how to fix it?

The script for the player stamina:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerStamina : MonoBehaviour
{
public int maxPlayerStamina = 100;
public int currentPlayerStamina;

public StaminaBar staminaBar;

// Start is called before the first frame update
void Start()
{
currentPlayerStamina = maxPlayerStamina;
staminaBar.SetMaxStamina(maxPlayerStamina);
}

// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.G))
{
LoseStamina(20);
}
if (Input.GetKeyDown(KeyCode.Mouse0))
{
}
if (Input.GetKeyDown(KeyCode.Mouse1))
{
}
}

{

staminaBar.SetStamina(currentPlayerStamina);
}
}


The script for the stamina slider:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class StaminaBar : MonoBehaviour
{
public Slider slider;

public void SetMaxStamina(int stamina)
{
slider.maxValue = stamina;
slider.value = stamina;
}

public void SetStamina(int stamina)
{
slider.value = stamina;
}
}


• Assume you're talking to someone who has never seen this video. Explain step by step what we need to do to create a Minimal Complete Verifiable Example of this problem. Include screenshots if it helps you explain where you're stuck. Remember we can't see your screen, so we don't know what you're dragging, where you're dragging it from, or where you're dragging it to, unless you show us or describe it in detail. Nov 12 '21 at 23:59
• When you crop your screenshots so tight like this, we can only see that there is an object called StaminaBar — we can't see where it is. Same goes for the Player Stamina script snippet. We can't tell whether that's on an object in the same scene as the StaminaBar, or in a prefab in your Assets folder, etc. Nov 13 '21 at 12:28

You have a GameObject called StaminaBar, but you are not showing if that GameObject has the StaminaBar Component attached to it. Please double-check if you actually dragged the StaminaBar script to your StaminaBar GameObject inside the Inspector, and try again to drag the GameObject to the field exposed by your GameObject containing the PlayerStamina class. This is mandatory because the script is looking for a GameObject with a StaminaBar component attached to it, otherwise it won't let you perform the drag & drop.
Your PlayerStamina script exposes a field of type StaminaBar, meaning that you can assign any GameObject with a StaminaBar Component to it. But, you cannot assign a GameObject that doesn't have such a Component, even if one of its children has it instead.
In order to drag the StaminaBar GameObject into the exposed field, make sure StaminaBar does have the StaminaBar Component itself. I try to guess that StaminaBar is an empty GameObject that contains the actual GameObject with a StaminaBar Component. This setup may be desirable for ad-hoc UI displacement with anchors. In this case, try and drag the child GameObject in the exposed field in the Inspector instead of its parent.