I’m Just starting out with the Unreal 4 engine and programming in general. I have been trying to follow various tutorials trying to get a grasp on how to build a simple game using C++ but have come across a section of code that I cant understand. I believe this code comes from Epic’s “Introduction to UE4 Programming” video series on Youtube, However as this is my first attempt at creating something without a tutorial I may have found this elsewhere.
The Code is the following:
static ConstructorHelpers::FObjectFinder<UBlueprint> PlayerPawnObject(TEXT("Blueprint'/Game/Blueprints/BP_playerPawn.BP_playerPawn'"));
if (PlayerPawnObject.Object != NULL)
{
DefaultPawnClass = (UClass*)PlayerPawnObject.Object->GeneratedClass;
}
Which is located in the constructor for my game mode class. This code sets a blueprint of my PlayerPawn class to be the default pawn class for my game mode. When The game is run the static mesh component associated with the blueprint is displayed as expected.
Even though this code is working, I am unable to understand the syntax that has been used. Could someone please try to explain in simple terms what is happening here. I will try to explain each line below as I currently understand them.
static ConstructorHelpers::FObjectFinder<UBlueprint> PlayerPawnObject(TEXT("Blueprint'/Game/Blueprints/BP_playerPawn.BP_playerPawn'"));
We are creating an object called PlayerPawnObject that holds information about the blueprint found in the given directory. I’m assuming that ConstructorHelpers::FObjectFinder somehow defines a data type but I don’t really understand what is going on here. In particular I don’t understand the angled brackets . I also don’t understand how the blueprints directory is able to be used as what seems like an argument when defining a new object.
if (PlayerPawnObject.Object != NULL)
{
DefaultPawnClass = (UClass*)PlayerPawnObject.Object->GeneratedClass;
}
The If statement is being used to avoid errors in the event that the PlayerPawnObject could not be created.
DefaultPawnClass is a parameter that is inherited from the GameMode class which defines the default pawn class for the game mode.
(UClass*) is being used to cast PlayerPawnObject.Object->GeneratedClass as a UClass pointer ?
PlayerPawnObject.Object does not make sense to me as I assumed that PlayerPawnObject was an object its self.
I am assuming GeneratedClass is a method within PlayerPawnObject that returns a reference to the objects class?
Why are empty parenthesis not required here? ie. PlayerPawnObject.Object->GeneratedClass() ?
Any assistance in helping me understand this code, or and documentation or reference material that may clear things up would be appreciated. Thanks