Object registration problem after loading new scene
by Thomas Wrather · in Torque X 2D · 12/06/2007 (7:12 pm) · 6 replies
When my game starts I create a worldCam object, register it, and then mount it to the player.
To go to the next game level, I UnloadLastScene and then Load a new scene.
When I try to Mount the worldCam to the player on the next level I get an assertion failure "Mounter and mountee must either both be registered or neither registered."
I checked the IsRegistered property on both the player and the worldCam. The player was registered but the worldCam was not.
So, before mounting, I added code like: if (!worldCam.IsRegistered) register(worldCam). This gives an assertion failure of "Registering an object which is already registered"
This leaves me confused. How is it that the worldCam is not registered, but I'm not allowed to register it?
To go to the next game level, I UnloadLastScene and then Load a new scene.
When I try to Mount the worldCam to the player on the next level I get an assertion failure "Mounter and mountee must either both be registered or neither registered."
I checked the IsRegistered property on both the player and the worldCam. The player was registered but the worldCam was not.
So, before mounting, I added code like: if (!worldCam.IsRegistered) register(worldCam). This gives an assertion failure of "Registering an object which is already registered"
This leaves me confused. How is it that the worldCam is not registered, but I'm not allowed to register it?
#2
12/08/2007 (6:50 pm)
What is the object ID out of curiousity of the camera? The only three cases that error can appear on is if the object is null, the object id is not zero, or the isRegistered is true.
#3
Since the object is not null and IsRegistered is false, I assume my problem is that the ObjectId is not 0. Any ideas how I managed to get an object unregistered, yet still have an Id? I have not explicitly unregistered the camera in my code. Is it getting unregistered by UnloadLastScene?
Here's a bigger snippet of the code:
SceneLoader.UnloadLastScene();
SceneLoader.Load(@"data\levels\levelData2.txscene");
worldCam_ = T2DSceneGraph.Instance.Camera as T2DSceneCamera;
if (worldCam_.IsUnregistered)
{
TorqueObjectDatabase.Instance.Register(camera);
}
12/08/2007 (8:12 pm)
ObjectId is 161.Since the object is not null and IsRegistered is false, I assume my problem is that the ObjectId is not 0. Any ideas how I managed to get an object unregistered, yet still have an Id? I have not explicitly unregistered the camera in my code. Is it getting unregistered by UnloadLastScene?
Here's a bigger snippet of the code:
SceneLoader.UnloadLastScene();
SceneLoader.Load(@"data\levels\levelData2.txscene");
worldCam_ = T2DSceneGraph.Instance.Camera as T2DSceneCamera;
if (worldCam_.IsUnregistered)
{
TorqueObjectDatabase.Instance.Register(camera);
}
#4
12/08/2007 (9:26 pm)
Just curious, Does your .txscene have a defined camera? I wonder what would happen if you used the DefaultCamera instead of Camera.
#5
You would have to create a new worldCam object for each level, but David's hint to use the DefaultCamera seems to be a more elegant way.
12/09/2007 (6:47 am)
The re-use of unregistered objects is not possible in Torque X (see Topic: Registering object already registered).You would have to create a new worldCam object for each level, but David's hint to use the DefaultCamera seems to be a more elegant way.
#6
12/09/2007 (8:58 am)
Thanks for your help. I created a new camera to get around my problem.
Torque Owner Thomas Wrather
{
TorqueObjectDatabase.Instance.Register(camera);
}
Gives an Assertion failed "Registering an object which is already registered". How is this possible?