[Original tutorial is based on UE 4.18, MINE is based on UE 4.25]

English Source address

To follow up the tutorial, create a new C++ class that inherits from Actor and name it CreateStaticMesh. Add the UStaticMeshComponent to the header file and name it whatever you want. In this case, I’ll name it “SuperMesh.” We set the variable’s UPROPERTY to VisibleAnywhere so that we can easily add a grid to the editor, as shown below.

 

Here is the final header code

 CreateStaticMesh.h

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "CreateStaticMesh.generated.h"

UCLASS(a)class UNREALCPP_API ACreateStaticMesh : public AActor
{
	GENERATED_BODY(a)public:	
	// Sets default values for this actor's properties
	ACreateStaticMesh(a);protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay(a) override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

	UPROPERTY(VisibleAnywhere)
	UStaticMeshComponent* SuperMesh;
};
Copy the code

In the CPP file, we add a simple static grid component to the constructor of the Actor class. Use CreateDefaultSubobject to create a new UStaticMeshComponent that you can call whatever you want. In this case, I call this Mesh “My Super Mesh.”

Here is the final.cpP code.

CreateStaticMesh.cpp

#include "CreateStaticMesh.h"


// Sets default values
ACreateStaticMesh::ACreateStaticMesh()
{
 	// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	// Add static mesh component to actor
	SuperMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("My Super Mesh"));

}

// Called when the game starts or when spawned
void ACreateStaticMesh::BeginPlay(a)
{
	Super::BeginPlay(a); }// Called every frame
void ACreateStaticMesh::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}
Copy the code

Now in the editor, drag and drop your new actor. In the Actor Details pane, select the static mesh you want to add to the actor.