[C++] How to get a reference to a class in the scene within another class

Right, so coming from Unity, you could literally make a public reference and drag it in, or a private reference and use getcomponent.

However, Unreal seems to be super confusing and there is no obvious way to do it that i have found.

I am trying to access my class “ALevelGenerator” in my Gamemode. Through this code:

.h
public:
class ALevelGenerator* LevelCreator;

.cpp
in constructor
LevelCreator = Cast(GetComponentByClass(ALevelGenerator::StaticClass()));

P.S i have the file #included too. This does not compile. Any ideas?

You have to specify in what class you want to cast it in,
try:

LevelCreator = Cast<ALevelGenerator>( GetComponentByClass( ALevelGenerator::StaticClass() ));

Hope this helps,
Elias