Your code would crash anyway as you making function call on null pointer as MainActor is not set.
There no “class to class” communication, class is only declaring class of object, object which need to be created first (if it’s not created already (note that you code runs as part of the engine so there many object that sits in memory and you can get via various APIs) , then you can send function calls to created object. and you can create more then one… i mean all actors are AActors objects (as all actor classes base from that class). So if anything it’s “Object to Object” communication.
To make a function call or access object variables you need a pointer to actor (which technically is integer contianing memory address to object). You already made pointer variable
AGround_Setup_Ground* problem is it’s not set, so compiler don’t know what value to give when this variable is allocated in memory, thats why you got error. You need to get proper address to object first to set that pointer and there many ways to do this depending what you doing
All function that create objects like SpawnActor one you used in your code CreateDefaultSubobject, return pointer to newly created object and you keep it in variable to remember it and communicate with it (you did that with BillBoardActor). But if you not created the object oyu want to communicate, you need to access it via varius APIs. In you case you want to access actor owning your component, you can do that by calling GetOwner function that every compoent have:
But your code have other issue, you doing this in constructor and at this point you component is not attach to any actor, not to mention in UE4 constructor is called during creation of so called Class Default Object (CDO) on you module startup to store default values, so by convention constructor can only set default varable states, CreateDefaultSubobject is a actually special function that creates object containing default and that object it self will be created when main object is created, you can’t use it outside of constructor.
For this reason UE4 provides different event functions that you can override that are called in different stages of object initation. like OnRegister for example:
If not try other functions: