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);
*/
相关推荐
六点半88828 分钟前
【C/C++】速通涉及string类的经典编程题
c语言·开发语言·c++·算法
汤姆和杰瑞在瑞士吃糯米粑粑30 分钟前
string类(C++)
开发语言·c++
学霸小羊1 小时前
C++游戏
c++·游戏
码农豆豆2 小时前
4.C++中程序中的命名空间
开发语言·c++
Joker100852 小时前
C++初阶学习——探索STL奥秘——标准库中的priority_queue与模拟实现
c++
怀九日2 小时前
C++(学习)2024.9.19
开发语言·c++·学习·重构·对象·
KookeeyLena82 小时前
如何限制任何爬虫爬取网站的图片
开发语言·c++·爬虫
m_Molly2 小时前
vs2022配置opencv==4.9.0(C++)
c++·opencv
charon87782 小时前
Unreal Engine 5 C++: 编辑器工具编写入门(中文解释)
c++·ue5·编辑器·游戏引擎·虚幻
Ddddddd_1582 小时前
C++ | Leetcode C++题解之第421题数组中两个数的最大异或值
c++·leetcode·题解