So I created the following class in C++ called TutorialLevel, and it is derived from the engine class “ALevelScriptActor”.
.h
#pragma once
#include "CoreMinimal.h"
#include "Engine/LevelScriptActor.h"
#include "TutorialLevel.generated.h"
UCLASS()
class GAMEC_API ATutorialLevel : public ALevelScriptActor
{
GENERATED_BODY()
public:
ATutorialLevel();
protected:
virtual void BeginPlay() override;
};
.cpp
#include "TutorialLevel.h"
#include "Runtime/Engine/Classes/Kismet/KismetSystemLibrary.h"
#include "Engine.h"
ATutorialLevel::ATutorialLevel()
{
}
void ATutorialLevel::BeginPlay()
{
Super::BeginPlay();
ALevelScriptActor* currentLevel = Cast<ATutorialLevel>(()->GetLevelScriptActor());
}
I then created a BP class derived from this TutorialLevel C++ class, and I called this class TutorialLevelBP.
So, in essence, this line:
ALevelScriptActor* currentLevel = Cast<ATutorialLevel>(()->GetLevelScriptActor());
allows me to create a variable in the .cpp file to store a reference to the BP version of the level, which is what I want because the level being played in the game is actually a BP instance of the C++ class.
Here’s what I want to accomplish. You know how you can add actors to a level by dragging them into the level in the editor? Like say if I had a house actor, I could add that house to the level by dragging it from the content browser, instead of spawning it at runtime? When I worked with BP, I was able to create references to these specific actors that were already placed in the level by default, like this (https://imgur.com/a/IkTD3c4), or like this documentation (http://api.unrealengine.com/INT/Engine/Blueprints/UserGuide/Types/LevelBlueprint/index.html#referencingactors), and then from there I could get a reference back to this specific actor anywhere in the BP event graph. Now, in C++, I would like to do something similar where I get a reference to a specific actor.