Instancing Error
by Jeremy Dains · in Torque Developer Network · 08/31/2010 (8:17 pm) · 1 replies
I am getting a random instancing error using Torque X 2D. I am simply trying to access the object database and assign an object with a given name to a variable in code. Here is an example.
Game.Instance.SceneLoader.Load(@"data\levels\levelData.txscene");
T2DSceneObject _camera = TorqueObjectDatabase.Instance.FindObject<T2DSceneObject>("Camera");
T2DAnimatedSprite _player = TorqueObjectDatabase.Instance.FindObject<T2DAnimatedSprite>("player");
_camera.Mount(_player, "", true);
The exact error reads: NullReferenceException was unhandled; Object reference not set to an instance of an object. This refers to both the _camera and _player variables.
Here is some code from my levelData.txscene:
<AnimatedSprite name="player">
<CreateWithPhysics>false</CreateWithPhysics>
<CreateWithCollision>false</CreateWithCollision>
<ObjectType>
<object objTypeRef="t2dAnimatedSpriteType" />
</ObjectType>
<Pool>false</Pool>
<PoolWithComponents>false</PoolWithComponents>
<IsTemplate>false</IsTemplate>
<IsPersistent>false</IsPersistent>
<Layer>0</Layer>
<Size>
<X>26.250</X>
<Y>26.250</Y>
</Size>
<Position>
<X>-30.207</X>
<Y>16.963</Y>
</Position>
<Rotation>0</Rotation>
<CollisionsEnabled>true</CollisionsEnabled>
<Visible>true</Visible>
<VisibilityLevel>1</VisibilityLevel>
<FlipX>false</FlipX>
<FlipY>false</FlipY>
<SortPoint>
<X>0.000000</X>
<Y>0.000000</Y>
</SortPoint>
<AnimationData nameRef="YotoIdle01Animation" />
<StartFrame>0</StartFrame>
<RandomStart>false</RandomStart>
<PlayOnLoad>true</PlayOnLoad>
<RemoveOnFinished>false</RemoveOnFinished>
</AnimatedSprite>
I am clearly naming the object correctly and yet I have received this error randomly in several different instances. It is extremely annoying and I would very much like to find a verified solution to this issue I keep running into. Any help would be appreciated. Thanks
Game.Instance.SceneLoader.Load(@"data\levels\levelData.txscene");
T2DSceneObject _camera = TorqueObjectDatabase.Instance.FindObject<T2DSceneObject>("Camera");
T2DAnimatedSprite _player = TorqueObjectDatabase.Instance.FindObject<T2DAnimatedSprite>("player");
_camera.Mount(_player, "", true);
The exact error reads: NullReferenceException was unhandled; Object reference not set to an instance of an object. This refers to both the _camera and _player variables.
Here is some code from my levelData.txscene:
<AnimatedSprite name="player">
<CreateWithPhysics>false</CreateWithPhysics>
<CreateWithCollision>false</CreateWithCollision>
<ObjectType>
<object objTypeRef="t2dAnimatedSpriteType" />
</ObjectType>
<Pool>false</Pool>
<PoolWithComponents>false</PoolWithComponents>
<IsTemplate>false</IsTemplate>
<IsPersistent>false</IsPersistent>
<Layer>0</Layer>
<Size>
<X>26.250</X>
<Y>26.250</Y>
</Size>
<Position>
<X>-30.207</X>
<Y>16.963</Y>
</Position>
<Rotation>0</Rotation>
<CollisionsEnabled>true</CollisionsEnabled>
<Visible>true</Visible>
<VisibilityLevel>1</VisibilityLevel>
<FlipX>false</FlipX>
<FlipY>false</FlipY>
<SortPoint>
<X>0.000000</X>
<Y>0.000000</Y>
</SortPoint>
<AnimationData nameRef="YotoIdle01Animation" />
<StartFrame>0</StartFrame>
<RandomStart>false</RandomStart>
<PlayOnLoad>true</PlayOnLoad>
<RemoveOnFinished>false</RemoveOnFinished>
</AnimatedSprite>
I am clearly naming the object correctly and yet I have received this error randomly in several different instances. It is extremely annoying and I would very much like to find a verified solution to this issue I keep running into. Any help would be appreciated. Thanks
About the author
Torque Owner Jeremy Dains
For anyone else who may have this issue, check the properties for both your Torque2D and TorqueCore solutions. Make sure the Assembly name is labelled correctly.
For Torque2D the Assembly name must be "GarageGames.TorqueX.Framework2D"
For TorqueCore the Assembly name must be "GarageGames.TorqueX.Framework"
This completely resolved my instancing errors.
Hope this helps someone else