What is the proper way to have a class pointer, that will be set to each of its objects ? Have a definition as private member, and then ? What code is in the constructor or beginplay function ? how do I catch the object that has just been created ? AGameMode* p_AGameMode = ? (find the adress of this object) ?
I think you mean object pointers, not class pointers (UClass* or TSubclassOf). The answer depends on what object you searching for, lot of objects in UE4 keep refrence to eachother if they somewhat related, you need to search API reference to how to get specific things. Actor you operating in maybe already has pointer to what you want (foir example Pawn have Controller varable which points to controller that current possess it). If you searching for something global like current game AGameMode, good place to search is UEngine (main engine class) which can be accessed from any point of the code using global variable GEngine
Or UWorld (world class) which can be accessed via () in any actor or (more risky way of doing it, aspecially in editor build), GWorld global varable
You can get current AGameMode from UWorld using this function:
there also easy cast version:
Also this is importent to understand, don’t set objects varables in constructor other then components, constructor is executed only once during creation Class Default Object where engine and game state is not fully established and many things are not initiated yet, so if you do ()->GetAuthGameMode() in there, it will make editor crash when you start it (when CDO is created), because () will return null, use BeginPlay() insted.
Thank you.
UObjects also have an Outer afaik, which is essentially their parent owning object (most of the time).
I now have my object pointer saving the castet gamemode object ( in beginplay()) I want to use this now as a reference in blueprint, but if I choose the Getter for it in blueprint, it wants a target. So why is that happen, isnt the pointer supposed to be the target ?