The UVK::Level
class comprises 2 distinct code regions
The level contains a pointer to a Game Mode
class, which contains all other gameplay class types except the level itself, the GameInstance
and the Scriptable Objects
. More about the Game Mode
class and the Level
’s relationship with it will be explained in the Game Mode
chapter.
The level class also handles saving and loading level files.
To open a new level, call the
template<typename T>
static void open(String location)
function. As a template parameter put the type of the level you want to open, as your function parameter put the location to your level starting from the Content/
folder (don’t list an extension)
To save a level call the
static void save(String location);
function with the location starting from the Content/
folder (don’t list an extension)
The level class offers so called get
functions to make navigating the class hierarchy easier and less verbose.
static PlayerController* getPlayerController(Level* lvl);
static Pawn* getPawn(Level* lvl);
static GameState* getGameState(Level* lvl);
static PlayerState* getPlayerState(Level* lvl);
To change the ambient colour and intensity, call the
static FVector4& getAmbientLighting()
function. The return value is a 4 argument vector with the x
, y
and z
values corresponding to r
, g
and b
. The fourth value(w) is the intensity of the lighting.
To change the background colour, call the
static FVector4& getSceneColour();
function. The return value is a reference to a 4 value vector with x
, y
, z
and w
corresponding to r
, g
, b
and a
To change the name(not to be confused with the filename) of the level, call the
static std::string& getLevelName();
function. It returns a reference to a standard string containing the name.
You can use the cast function to convert a generic Level
pointer into its original type, like this
auto* originalLevel = Level::cast<YourOriginalLevelType>(aPointerToAGenericLevel);
The function for opening levels is kind of complicated, so here comes an explanation:
When a user calls the
template<typename T>
static void open(String location)
{
global.openFunction = [location]()
{
global.currentLevel->endPlay();
delete global.currentLevel;
T* lvl = new T();
global.currentLevel = lvl;
T::openInternal(location);
global.currentLevel->beginPlay();
};
}
function, a global variable of type std::function
, member of the UVK::UVKGlobal
class, is assigned to a lambda. The following lambda only needs to capture the location
variable, since that is the only thing the function needs. After it is assigned, the function will be called next frame.
When the lambda is executed 6 things will happen
begin
function for the new level will be calledNow we need to move to a different file. GLPipeline.cpp
L105 calls a function from the UVK::UVKGlobal
class called
global.finalizeOpening();
. This function is called every frame if the editor isn’t in use. What it does is, it calls the function pointer that was assigned in the original open function, and then resets the function pointer to an empty lambda.