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
相关推荐
帅_shuai_4 小时前
UE Json 序列化和反序列化
c++·ue5·json·虚幻引擎
gshh__3 天前
SuperMap Hi-Fi 3D SDK for Unreal 如何修改模型选中高亮颜色
ue5·游戏引擎·supermap
AI视觉网奇3 天前
ue5 随机数学习笔记
ue5
曼巴UE53 天前
UE GamePlayTag
c++·ue5·ue
AI视觉网奇4 天前
ue安装插件方法笔记
笔记·ue5
AI视觉网奇4 天前
ue 动作 动画学习笔记
笔记·ue5
吴梓穆4 天前
UE5 时间轴调整播放速度
ue5
会思考的猴子4 天前
UE5 笔记二 GameplayAbilitySystem Attributes & Effects
笔记·ue5
UTwelve4 天前
【UE】材质与半透明 - 01.将半透明作为后期材质
ue5·材质·着色器
AI视觉网奇5 天前
ue重定向学习笔记
笔记·ue5