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);
*/
相关推荐
炘爚4 分钟前
C++(移动构造、移动赋值、完美转发)
前端·c++
环黄金线HHJX.7 分钟前
BaClaw龙虾打字
开发语言·人工智能·算法·编辑器
王老师青少年编程9 分钟前
csp信奥赛c++之字符数组与字符串的区别
c++·字符串·字符数组·csp·信奥赛
格林威27 分钟前
GigE Vision 多相机同步优化方案: PTP + 硬件触发 + 时间戳对齐
c++·人工智能·数码相机·计算机视觉·c#·视觉检测·工业相机
Codiggerworld28 分钟前
Elisp入门:让编辑器听懂你的话
编辑器
要退休的攻城狮29 分钟前
跳到千问挖的坑里去了
c++·人工智能·嵌入式硬件·visualstudio
深邃-30 分钟前
C语言内存函数
c语言·开发语言·数据结构·c++·算法
旺仔.29136 分钟前
八大排序:(三)快速排序
数据结构·c++·算法
刺心疯1 小时前
VScode集成openClaw使用OpenClaw Node for VS Code插件(右键没有openClaw)
vscode·编辑器
6Hzlia1 小时前
【Hot 100 刷题计划】 LeetCode 438. 找到字符串中所有字母异位词 | C++ 滑动窗口题解
c++·算法·leetcode