Tencent / UnLua

A feature-rich, easy-learning and highly optimized Lua scripting plugin for UE.
Other
2.28k stars 619 forks source link

[Bug] Initializer 的结果被蓝图默认值覆盖 #572

Open KarryCharon opened 1 year ago

KarryCharon commented 1 year ago

Actor A 定义初始化

---@type A_C
local M = UnLua.Class()
function M:Initialize(Initializer)
    if Initializer then
        self.DDD = Initializer[0]
        print("Construct: " .. self.DDD)
    end
end
return M

以下为构造 A 的逻辑

local M = UnLua.Class()

function M:ReceiveBeginPlay()
    local b_cls = UE.UClass.Load("/Game/Test/lua/A.A_C")
    local params = {}
    params[0] = 10.2
    local b = NewObject(b_cls, self, nil, "Test.A", params)
    print("Finished: " .. b.DDD)

end
return M

构造完成后 DDD变量会被 蓝图中 DDD变量的默认值覆盖 ,导致Initialize不起作用

aleverys commented 1 year ago

Initializer里面只能初始化Lua属性 不能初始化C++里的属性 调用时候对象的构造函数都没走完呢