Game Development Community

No components in objects cloned from templates with pooled components after reloading a scene?

by Jacob Lynch · in Torque X 2D · 07/16/2009 (11:53 pm) · 4 replies

Here is my (example) setup:

templates.txscene:
apple template, which is pooled with components, and persistent. Contains a foo component

mainScene.txscene:
spawnerObject with a component that spawns an apple using the template and deletes the spawnerObject

Here's what happens:

On the initial startup of the game:
templates.txscene is loaded
mainScene.txscene is loaded
spawnerObject is registered
spawnerObject clones an apple with a foo component and deletes itself

-- At this point I press the key I have bound to cause a level reset

Here's what happens next:
Sceneloader unloads mainScene.txscene
Sceneloader loads mainScene.txscene
enter the spawnerObject register function
spawnerObject clones an apple, but this apple doesn't have any components.

If I go to the templates.txscene and check only "Pool" instead of "Pool with components" then after reloading the level it will clone the apple with the foo component. Is this expected behavior? I didn't expect it! I thought pooling with components would let it clone the object with components faster. Any ideas would be appreciated, although the 'workaround' doesn't really cost me anything.

Now if I can just figure out why my player object causes the game to crash when I do the level reloading...

Edit: The template objects themselves do actually have the components, but the cloned objects do not.

#1
07/22/2009 (12:58 am)
Suppose on level reset you were to not unload the mainScene.txscene, but merely loaded it again?
#2
07/24/2009 (12:09 am)
Thanks for your response! If you do not perform an unload command, then nothing will happen when you do the load command. I think it must check and see that the scene is already loaded and abort the operation.
#3
11/03/2010 (1:43 am)
I was running into this problem again, and this time I figured out what caused it. If you clone an object and then add a component to it before registering it, then clone an object from the original template again it will try to reuse the previous object, but it will see that the number of components doesn't match. Then it will set the components to null.

So I guess I will redo some code so that it doesn't need to add components to cloned objects.
#4
11/03/2010 (5:38 am)
Thanks for sorting this out. I had a pooling with components problem but I just put it on the backburner for now and merely cloned it as a template without pooling.

This would definately be the problem I'm having. I'll have to re-think my templates as well.

-Added to the TDN-