This part is mainly to use code in C++ to output a line of text on the game interface
The first step is to create a new C++ version of the project file. After version 4.12, the Vs compiler will be automatically opened after creation.
As shown below
Click to compile in VS, wait for the tape to compile, the first time the waiting time is longer , The specific time is more specific and its configuration depends on
After the first compilation is completed, it proves that our project is correct Yes, this way, when the post-compilation fails, it can be ruled out that it was an error when the project was created
After the project is completed, you can Set the program to start the map
Select the edit item to set the map mode, set the default map
This time, every time the program runs, it will start our map by default
Create a new The GameModel class
As shown below
p>
After the creation is completed, the program will automatically open the VS compiler, and open the .H file and .CPP file by default
< br>
Everyone will see some files generated by default
#pragma once#include "GameFramework/GameMode.h"#include "MyGameMode.generated.h"/** */UCLASS()class M_C_TEST1_API AMyGameMode: public AGameMode{ GENERATED_BODY() };
UCLASS() pre>GENERATED_BODY()These codes are unique to UE4 Yes, when we compile, UE4 will recognize these files
After closing UE4, compile the program again
Pay attention to the current project size
At this time, we have to choose our own newly created game model to control the game
< img src="/wp-content/uploadshttp:/img.voidcn.com/vcimg/static/loading.png" alt="" d="5145758" s="59c_009" t="jpg">
< /p>
Add function declaration in .H file
virtual void BeginPlay() override;
Implemented in .cpp
void AMyGameMode::BeginPlay()
{
if (GEngine)
{
< /span>GEngine->AddOnScreenDebugMessage(-1, 8.f, FColor::Red, TEXT("Hello word"));
}< br> }In theory, running the game is fine, but I failed.
Next I will load a built-in To check it out