Switching t2dSceneObject to a new t2dSceneGraph
by Chad Kilgore · in Torque Game Builder · 08/08/2009 (4:33 pm) · 5 replies
I'm working on a trigger behavior to move the PC from his current scenegraph to a new scenegraph. However, when I remove the PC from scene A and add it to scene B, TGB crashes.
SceneConstant is a persistent t2dSceneWindow that contains references to 2 other t2dSceneWindows: ActiveLevel and StreamLevel.
Has anybody successfully moved an object from one SceneGraph to another? How did you do this without getting this crash? Thanks.
function LevelSwitchBehavior::onEnter(%this, %object)
{
if (%object != $Player)
return;
if (!isObject(SceneConstant.StreamLevel))
return;
if (SceneConstant.StreamLevel.Level $= "")
return;
SceneConstant.ActiveLevel = SceneConstant.StreamLevel;
SceneConstant.StreamLevel = $Player.SceneGraph;
$Player.removeFromScene();
$Player.addToScene(SceneConstant.ActiveLevel.getSceneGraph());
}SceneConstant is a persistent t2dSceneWindow that contains references to 2 other t2dSceneWindows: ActiveLevel and StreamLevel.
Has anybody successfully moved an object from one SceneGraph to another? How did you do this without getting this crash? Thanks.
#2
You can always do this:
08/09/2009 (3:56 pm)
When you move an object to another scene, you must reset its position as you have found out. The reason is that the object isn't placed into a "bin" when it is first added.You can always do this:
function t2dSceneObject::setSceneGraph( %this, %sceneGraph )
{
// Using this field will do some funky stuff in the background
// to help with the move.
%this.SceneGraph = %sceneGraph;
// Reset Object.
%this.setPosition( %this.Position );
}Give that a wack.
#3
08/09/2009 (4:59 pm)
I gave it a wack. The Player really does not like being moved into another SceneGraph. I've dismounted the camera from the Player and no other entities are mounted to it and it still crashes. It works for all other entities other than the Player.
#4
08/10/2009 (5:40 am)
I take my previous statement back. t2dSceneObject::setSceneGraph does *not* work with every entity other than the Player. It does not work with another pskActor entity. I tried moving a Drill into a different SceneGraph and the system crashed again. ...At least it is slowly getting narrowed down.
#5
04/28/2010 (12:46 pm)
I'm having this problem as well. Chad did you ever find a solution?
Torque 3D Owner Chad Kilgore
I am using the PSK. I added:
function PlayerClass::onAddToScene(%this, %scenegraph) { if (isObject($Player)) return; ... }So not to re-register custom states.