Hello,
you are right regarding the custom UIs: on scene close, they will be removed before the scripts are removed (which was a bug actually, and corrected now). But you say this also happens with scene objects? This shouldn't be the case. If you add new scene objects during simulation, then they will automatically be removed when simulation stops (you can change this behaviour in the
simulation settings dialog). But upon scene close all scene objects should still be there when the clean-up procedure of customization scripts is called. Can you confirm this?
If you create dynamically objects/UI/etc. in your customization script, then erase them upon customization script clean-up, you have a problem when you save your scene: the dynamically created objects will also be saved, and restored next time you load the scene. But the customization script will re-create those objects at scene load, and you will have duplicates of them. One way to avoid this is to keep track of the created objects inside of objects, e.g.:
This can be problematic when saving your scene (will create a duplicate at scene load):
Code: Select all
if (sim_call_type==sim_customizationscriptcall_initialization) then
h=simGetObjectAssociatedWithScript(sim_handle_self)
cube=simCreatePureShape(0,2,{0.1,0.1,0.1},1)
end
if (sim_call_type==sim_customizationscriptcall_cleanup) then
simRemoveObject(cube)
end
This solves the problem:
Code: Select all
if (sim_call_type==sim_customizationscriptcall_initialization) then
h=simGetObjectAssociatedWithScript(sim_handle_self)
-- Remove the objects I created previously:
local allObjects=simGetObjectsInTree(sim_handle_scene)
for i=1,#allObjects,1 do
local data=simReadCustomDataBlock(allObjects[i],'iCreatedThatObject')
if data then
simRemoveObject(allObjects[i])
end
end
-- Create objects and tag them as 'iCreatedThatObject':
cube=simCreatePureShape(0,2,{0.1,0.1,0.1},1)
simWriteCustomDataBlock(cube,'iCreatedThatObject','1')
end
if (sim_call_type==sim_customizationscriptcall_cleanup) then
simRemoveObject(cube)
end
For custom UIs, the approach is similar, but a little bit different, since you cannot write tags to custom UIs: you will have to store their name in a scene object (using the handle doesn't work, since handles are not guaranteed to stay the same from one scene instance to the next).
Cheers