UnLua访问C++属性、动态生成Actor

一、访问C++属性、动态生成Actor

1、在C++类MyBaseActor中新增蓝图可编辑属性:Name

cpp 复制代码
public:
	UPROPERTY(EditAnywhere)
	FString Name;

2、在继承自C++的蓝图子类BP_BaseActor中给Name赋值

3、在Lua中实现点击按钮动态生成Actor,并访问其Name属性

lua 复制代码
function WBP_FirstLua_C:Construct()
	self.btnTest.OnPressed:Add(self,WBP_FirstLua_C.OnClickTest)
end

function WBP_FirstLua_C:OnClickTest()
	local World = self:GetWorld()
	if not World then
		return
	end
	--加载蓝图类,注意文件路径格式:蓝图名.Lua类名
	local ActorClass = UE.UClass.Load("/Game/MyLuaTest/BP_BaseActor.BP_BaseActor_C")
	if not ActorClass then
		return
	end
	--动态生成一个actor
	local Rotation = UE.FQuat(1,1,1,1)
    local Translation = UE.FVector(1,1,1)
    local Scale = UE.FVector(1,1,1)
    local Transform = UE.FTransform(Rotation, Translation, Scale)
	local Actor = World:SpawnActor(ActorClass,Transform,UE.ESpawnActorCollisionHandlingMethod.AlwaysSpawn,self,self,"")
	if not Actor then
		return
	end

	self.Actor = Actor
	print("MyBaseActor'Name is "..self.Actor.Name)
end
相关推荐
吴梓穆2 天前
UE5 重新编译插件版本
ue5
HECUgauss2 天前
UE5 使用过程遇到的问题
ue5
小白学过的代码2 天前
ue5.4和webul通信
开发语言·javascript·ue5
m0_552200822 天前
《UE5_C++多人TPS完整教程》学习笔记40 ——《P41 装备(武器)姿势(Equipped Pose)》
c++·游戏·ue5
漫游者Nova2 天前
虚幻引擎Unreal Engine5恐怖游戏设计制作教程,从入门到精通从零开始完整项目开发实战详细讲解中英字幕
ue5·游戏引擎·虚幻·游戏开发完整教程·恐怖游戏开发
ue星空4 天前
UE5音频技术
ue5
帅_shuai_14 天前
UE5 游戏模板 —— FirstShootGame
游戏·ue5
吴梓穆15 天前
UE5 手动停止Delay定时器
ue5
AgilityBaby17 天前
UE5蓝图按键输入绑定学习笔记
笔记·学习·ue5·蓝图
涟涟涟涟17 天前
UE5错误 Linux离线状态下错误 请求失败libcurl错误:6无法解析主机名
linux·ue5