UE5 C++中 Actor内填加编辑器内模型

基础操作,总是忘记,记录下来备忘,未完待续。。。

cpp 复制代码
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

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

UCLASS()
class BUTTONCTEST_API AMyTaskTestClass : public AActor
{
	GENERATED_BODY()

public:
	// Sets default values for this actor's properties
	AMyTaskTestClass();
	//可在编辑器内实时调用
	virtual void OnConstruction(const FTransform& Transform) override;

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

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

private:
	UPROPERTY(VisibleAnywhere)
	UStaticMeshComponent* TestMesh;
	UPROPERTY(VisibleAnywhere)
	USceneComponent* DefaultSceneRoot;
};
cpp 复制代码
// Fill out your copyright notice in the Description page of Project Settings.


#include "MyTaskTestClass.h"

#include "UObject/ConstructorHelpers.h"
#include "Engine/StaticMesh.h"

#include "HAL/Runnable.h"
#include "HAL/RunnableThread.h"


// Sets default values
AMyTaskTestClass::AMyTaskTestClass()
{
	// 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;

	DefaultSceneRoot = CreateDefaultSubobject<USceneComponent>(TEXT("DefaultSceneRoot"));
	RootComponent = DefaultSceneRoot;
	TestMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("TestMesh"));
	TestMesh->SetupAttachment(DefaultSceneRoot);
	
	
}

void AMyTaskTestClass::OnConstruction(const FTransform& Transform)
{
	Super::OnConstruction(Transform);

	static ConstructorHelpers::FObjectFinder<UStaticMesh>MeshAsset1(TEXT("/Game/Torus_123.Torus_123"));
	if (MeshAsset1.Succeeded())
	{
		TestMesh->SetStaticMesh(MeshAsset1.Object);
	}
	static ConstructorHelpers::FObjectFinder<UStaticMesh>MeshAsset2(TEXT("/Game/Torus_234.Torus_234"));
	if (MeshAsset2.Succeeded())
	{
		TestMesh->SetStaticMesh(MeshAsset2.Object);
	}
}

// Called when the game starts or when spawned
void AMyTaskTestClass::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void AMyTaskTestClass::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
}

/*
这是一个简单的函数,它接受两个整数并返回它们的和
int32 Add(int32 a, int32 b) {
	return a + b;
}

// 在某个地方定义一个函数指针,并将它指向Add函数
int32 (*FuncPtr)(int32, int32) = Add;

// 然后,你可以使用函数指针来调用Add函数
int32 Sum = FuncPtr(2, 3);
*/
相关推荐
逆小舟1 小时前
【C/C++】指针
c语言·c++·笔记·学习
江公望1 小时前
Qt QtConcurrent使用入门浅解
c++·qt·qml
我是华为OD~HR~栗栗呀1 小时前
23届考研-Java面经(华为OD)
java·c++·python·华为od·华为·面试
爱吃喵的鲤鱼2 小时前
仿mudou——Connection模块(连接管理)
linux·运维·服务器·开发语言·网络·c++
郝学胜-神的一滴2 小时前
使用Linux的read和write系统函数操作文件
linux·服务器·开发语言·数据库·c++·程序人生·软件工程
2301_803554523 小时前
C++联合体(Union)详解:与结构体的区别、联系与深度解析
java·c++·算法
pu_taoc3 小时前
深入剖析:基于epoll与主从Reactor模型的高性能服务器设计与实现
服务器·c语言·c++·vscode
初圣魔门首席弟子3 小时前
c++ bug 函数定义和声明不一致导致出bug
开发语言·c++·bug
bkspiderx4 小时前
C++设计模式之行为型模式:中介者模式(Mediator)
c++·设计模式·中介者模式
敢敢J的憨憨L4 小时前
GPTL(General Purpose Timing Library)使用教程
java·服务器·前端·c++·轻量级计时工具库