Can't Access other variables with GetComponent

Hello. I have a fairly straightforward code:

public class Battle_Manager : MonoBehaviour 
{	
	private HeroStats _Cube;
		
	void Awake()
	{
		_Cube = GameObject.Find ("Cube").GetComponent<HeroStats>() as HeroStats;
		_Cube.Hero = GameObject.Find("Cube");
		
	}

This much works. It’s just when I add in things such as…

public class Battle_Manager : MonoBehaviour 
{	
	private HeroStats _Cube;
		
	void Awake()
	{
		_Cube = GameObject.Find ("Cube").GetComponent<HeroStats>() as HeroStats;
		_Cube.Hero = GameObject.Find("Cube");
		_Cube.Base.Health = 100;
		
	}    	
}

That I experience problems. I created a reference to my BaseStat class, my ModifiedStat class, and my Equipment class in the HeroStats class, and it seems that it won’t allow me to pull from it without getting a NullReferenceException.

Also, I’ve tried both using GetComponent<>() and GetComponent<>() as x… still can’t access anything because it’s not “assigned” to the object.

Thanks for any help!

Doing this GameObject.GetComponent() as HeroStats is redundant as the method already returns an object of type HeroStats, unless the script isn’t attached to your GameObject, for which it then returns null.

Now, I see that you get a reference to a “Cube” GameObject and use that to intialize your _Cube variable, and your “Hero” variable. You can simply do this so that you don’t have to use GameObject.Find on the same object twice since that method is quite expensive.

GameObject temp = GameObject.Find ("Cube");
_Cube = temp.GetComponent<HeroStats>();
_Cube.Hero = temp;

Then, you call_Cube.Base.Health = 100; but you never initialized the object “Base” what type is that. Were you supposed to find another GameObject there?