Game Development Community

Possible bug in clone object code?

by John Bura · in Torque X 2D · 12/03/2010 (2:16 pm) · 3 replies

So I started to build a giant level with the intention of splitting it up. After I split it up, everything works fine except for the .clone() code.

Now I haven't changed anything. The spawned objects are still in their spot and are still named. Whenever I have code like this it send back a null reference.

T2DSceneObject theSpawn = _spawnObject.Clone() as T2DSceneObject;

But the objects are clearly in the scene in TBX.


Im also thinking it could be the way I am disposing my last level. Here is my level changing code
Game.Instance.SceneLoader.Unload(@"datalevelsLevel1.txscene");

            GuiPlay2 playGUI = new GuiPlay2();
            GUICanvas.Instance.SetContentControl(playGUI);
            Game.Instance.SceneLoader.Load(@"datalevelsLevel2.txscene");

            GUICanvas.Instance.SetContentControl(playGUI);

Can anybody help me out? :)

#1
12/03/2010 (7:07 pm)
I've never had to deal with that problem, but one thing I would try is to compare the objects in the old XML file compared to the new, and see if everything is there.
#2
12/05/2010 (3:49 am)
Yup, I've not run into this either. Usually if my spawn object is null, its something i did wrong, like misnamed a variable inside my getters and setters.
#3
12/07/2010 (2:06 pm)
Question. Are you using the Torque X CEV? There are issues when using multiple scene graphs with the stock Torque X. When you register your object, it will add itself to the first scene graph it finds, instead of the last scene graph loaded. It is possible it is adding itself to the scene you are unloading.

EDIT: Actually, it looks like you aren't loading two scenes at once. For some reason I thought you were. Is it possible your object is disposed of? Clone returns null if the object you are cloning has already been disposed.