I have some trouble retrieving a ScriptObject’s Vector3 after reloading a saved scene.
Here is a simplified version of what I’m doing in lua:
scene_ = Scene()
local node = scene_:CreateChild(“MyNode”)
MyObject = ScriptObject()
self.destination = Vector3(10, 0, 10)
self.destination = deserializer:ReadVector3()
print(self.destination:ToString()) – Retrieval is OK
function HandleUpdate(eventType, eventData)
if input:GetKeyPress(KEY_F5) then scene_:SaveXML(fileSystem:GetProgramDir()…“Data/Scenes/TempExport.xml”) end
if input:GetKeyPress(KEY_F7) then scene_:LoadXML(fileSystem:GetProgramDir()…“Data/Scenes/TempExport.xml”) end
After reloading the scene, deserialization is OK but self.destination is immediately overwritten to an almost Vector3.ZERO
You do not need write load and save functions for it. Self.desternation will be saved as attribute automatic.
You can check your saved xml file.
Unfortunately issue is still the same with or without load and save.
By the way, how can you determine when a variable needs load and save?
It’s cool to have it loaded/saved automatically.
It is a bug in setting user type attribute, I have fixed it. You can check it. Thanks.
You don’t need write your load and save function for attribute in Lua script object. But I prefer you write a setting for it. like:
self.destination = Vector3(value)
The setter function name must with “Set + VarianceName” (first character need in upper).
Many thanks for helpful fix and tips
Maybe we should remove unnecessary load/save variables in sample 18 (onGround, okToJump and inAirTimer) as they are misleading.
Don’t remove these functions, but you can remove the attribute load code, just keep controls.yaw and pitch.
self.controls.yaw = deserializer:ReadFloat()
self.controls.pitch = deserializer:ReadFloat()