UnLua访问C++属性、动态生成Actor
一、访问C++属性、动态生成Actor
1、在C++类MyBaseActor中新增蓝图可编辑属性:Name
public:
UPROPERTY(EditAnywhere)
FString Name;
2、在继承自C++的蓝图子类BP_BaseActor中给Name赋值
3、在Lua中实现点击按钮动态生成Actor,并访问其Name属性
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
原文地址:https://blog.csdn.net/axin7c8/article/details/142349451
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!