Game Development Community

RemoveFromScene() deletes mounted objects

by Tim Doty · in Torque Game Builder · 10/13/2005 (5:14 am) · 4 replies

I don't see why this would be desirable behavior so I assume it is a bug. First I verified that removeFromScene() wasn't removing the object. The following adds a sprite, draws it, adds it to the scene, removes it and adds it again. All works beautifully.

$t = new fxStaticSprite2D();
$t.setImageMap(someImageMap);
$t.setSize("30 40");
$t.addToScene(t2dSceneGraph);
$t.removeFromScene();
$t.addToScene(t2dSceneGraph);

The following loses the static sprite.

$t2 = new fxSceneObject2D();
$t2.addToScene(t2dSceneGraph);

$t = new fxStaticSprite2D();
$t.setImageMap(someImageMap);
$t.setSize("30 40");
$t.addToScene(t2dSceneGraph);
$t.mount($t2);

$t2.removeFromScene();
$t2.addToScene(t2dSceneGraph);

$t.dump()

The scene object survives the removal, but not the mounted sprite (the dump() generates an error as the object can't be found). This can be worked around by dismounting first, of course, but if anything I'd expect the child objects to be removed and added back to the scenegraph rather than losing/deleting them.

#1
10/13/2005 (8:12 am)
From the docs

Quote:
mount(fxSceneObject2D, [offsetX / offsetY], [mountForce], [trackRotation?], [sendToMount?], [ownedByMount?] , [inheritAttributes?])

ownedByMount? Indicates whether the object is to be owned by the object its mounting to. What this means is that when the object that we're mounting to, is deleted, this object is automatically deleted. This is extremely useful for objects that are mounted that you don't want to explicitly track. The default is true.

Have you tried it with ownedByMount set to false?

--
Hans
#2
10/13/2005 (3:38 pm)
No, but that other than being another possible workaround it doesn't alter things. The objects aren't being deleted, they are being added to/removed from scenegraphs.

Currently I have it coded dismount() before altering the scenegraphs and then mount() again. A bit annoying, but as it is already coded... If I do any more with that I'll certain try that as it would be an easier workaround.

Thanks for the suggestion.
#3
10/13/2005 (3:58 pm)
Well, adding and removing an object several times to the scenegraph might not be the best way to achieve what you're after. Maybe using setVisible() would be a better idea?

--
Hans
#4
10/13/2005 (4:16 pm)
Its not a matter of adding and removing from one scenegraph -- that would be rather pointless. Its a matter of changing what scenegraph an object is in. In this case, compound objects. You have to remove an object in a scenegraph from that to add it to a different one. All well and good, but if you have objects mounted when you do the removeFromScene() call they are deleted.

That is not documented as being intended and it is not desirable behavior, hence the bug report.