We're now going to create a new C++ class with the following steps:
MyNewActor
. Hit Create Class. After it adds the files to the project, open MyNewActor.h
in Visual Studio. When you create a new class using this interface, it will generate both a header file and a source file for your class.BeginPlay
event. BeginPlay
is called once the game has started (in a multiplayer game, this might be called after an initial countdown, but in our case, it will be called immediately).MyNewActor.h
file (which should already be open at this point) should contain the following code after the GENERATED_BODY()
line:public: virtual void BeginPlay();
MyNewActor.cpp
, add a log that prints Hello, world! in the void AnyNewActor::BeginPlay()
function, which runs as soon as the game starts:void AnyNewActor::BeginPlay() { Super::BeginPlay(); GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("Hello World!")); }
MyNewActor
(there's a search bar to help you find it) and drag it into the scene view, which is the level viewport. It's invisible, so you won't see it or be able to click on it. However, if you scroll the Scene/World Outliner pane (on the right-hand side) to the bottom, you should see the MyNewActor1 actor has been added to the scene:Congratulations, you have created your first actor class in Unreal.
18.227.102.50