Game Development Community

Deleting a mounted object will cause the object to not mount the next time it is created [RESOLVED]

by Randy Lutcavich · in Torque X 2D · 09/22/2009 (2:22 pm) · 2 replies

Functionality:
I have a blue dot that is controlled by the player (well kind of, it is actually mounted to a yellow dot which is controlled by the player) and every time the player presses a button (Keyboard: J, Controller: X) a blue lightning attack object will spawn, mount to the blue dot and then be appropriately offset. Then after a set amount of time the new object is deleted and the player is allowed to fire again.

Problem:
The second time the new blue attack object is created it does not mount.

Code:
protected void _FireBlue()
        {
            if (_delayRemaining <= 0)
            {
                // Left - Clone a particular projectile from the template.
                T2DSceneObject LeftBlueProjectileObj = TorqueObjectDatabase.Instance.CloneObject<T2DSceneObject>("BlueProjectileTemplate");

                // Register the new object
                LeftBlueProjectileObj.Name = "LeftBlueProjectile";
                TorqueObjectDatabase.Instance.Register(LeftBlueProjectileObj);

                //Mount the new object to the Blue Dot
                T2DSceneObject BlueDot = TorqueObjectDatabase.Instance.FindObject<T2DSceneObject>("BlueDot");
                LeftBlueProjectileObj.Mount(BlueDot, "LinkPoint1", false);

                //Offset the position based on the position of the objects that's shooting
                Vector2 NewLeftBluePosition = SceneObject.Position;
                NewLeftBluePosition.X = NewLeftBluePosition.X - 20;
                NewLeftBluePosition.Y = NewLeftBluePosition.Y - 2;
                LeftBlueProjectileObj.Position = NewLeftBluePosition;
                LeftBlueProjectileObj.Layer = SceneObject.Layer + 1;


                // Up - Clone a particular projectile from the template.
                T2DSceneObject UpBlueProjectileObj = TorqueObjectDatabase.Instance.CloneObject<T2DSceneObject>("BlueProjectileTemplate");



                //Register the new object
                UpBlueProjectileObj.Name = "UpBlueProjectile";
                TorqueObjectDatabase.Instance.Register(UpBlueProjectileObj);

                //Mount the new object to the Blue Dot
                UpBlueProjectileObj.Mount(BlueDot, "LinkPoint1", false);

                //Offset the position based on the position of the objects that's shooting
                Vector2 NewUpBluePosition = SceneObject.Position;
                NewUpBluePosition.X = NewUpBluePosition.X - 2;
                NewUpBluePosition.Y = NewUpBluePosition.Y - 20;
                UpBlueProjectileObj.Position = NewUpBluePosition;
                UpBlueProjectileObj.Layer = SceneObject.Layer + 1;
                UpBlueProjectileObj.Rotation = 90;


                // Down - Clone a particular projectile from the template.
                T2DSceneObject DownBlueProjectileObj = TorqueObjectDatabase.Instance.CloneObject<T2DSceneObject>("BlueProjectileTemplate");


                //Register the new object
                DownBlueProjectileObj.Name = "DownBlueProjectile";
                TorqueObjectDatabase.Instance.Register(DownBlueProjectileObj);

                //Mount the new object to the Blue Dot
                DownBlueProjectileObj.Mount(BlueDot, "LinkPoint1", false);

                //Offset the position based on the position of the objects that's shooting
                Vector2 NewDownBluePosition = SceneObject.Position;
                NewDownBluePosition.X = NewDownBluePosition.X - 3;
                NewDownBluePosition.Y = NewDownBluePosition.Y + 17;
                DownBlueProjectileObj.Position = NewDownBluePosition;
                DownBlueProjectileObj.Layer = SceneObject.Layer + 1;
                DownBlueProjectileObj.Rotation = 270;

                // limit the rate-of-fire and how long the blue attack stays on screen
                _delayRemaining = 0.75f;
                _killBlue = 0.2f;
                _blueFired = true;

            }


        }

public virtual void ProcessTick(Move move, float dt)
        {
            if (move != null && move.Buttons[0].Pushed == true)
            {
                _Fire();
            }
            if (move != null && move.Buttons[1].Pushed == true)
            {
                _FireBlue();
            }

            // dt is the amount of time that has passed since the last tick
            _delayRemaining -= dt;
            _killBlue -= dt;

            if (_killBlue <= 0 && _blueFired)
            {
                T2DSceneObject UpPlacedBlue = TorqueObjectDatabase.Instance.FindObject<T2DSceneObject>("UpBlueProjectile");
                UpPlacedBlue.MarkForDelete = true;

                T2DSceneObject DownPlacedBlue = TorqueObjectDatabase.Instance.FindObject<T2DSceneObject>("DownBlueProjectile");
                DownPlacedBlue.MarkForDelete = true;

                T2DSceneObject LeftPlacedBlue = TorqueObjectDatabase.Instance.FindObject<T2DSceneObject>("LeftBlueProjectile");
                LeftPlacedBlue.MarkForDelete = true;

                _blueFired = false;
            }


        }

Solution:
Uncheck 'pool with components' for the lightning attack object.

#1
09/22/2009 (2:38 pm)
Note that I have tried dismounting the object before deletion but that doesn't solve the problem.
#2
09/22/2009 (3:47 pm)
The solution was in the forums after all.
www.garagegames.com/community/forums/viewthread/78699