0 Favourites

How do I delete previously created instance?

  • Hi. I tried to search the forums but found none to help me solve. As the title says, how do I delete previously created instance of an object? I provided an image of what I am currently working on. The gray square acts as the bullet that when on clicked and if aligned, it will move at the brown circle and rotate there, and then another circle should be created by being spawned at those small red circles. But then I wanted the blue circle to be deleted once the bullet moves to another. I'm stuck at the moment and can't seem to find a way to do it. Any help would be appreciated!

  • You spawn a new blue circle and you want the previous blue circle to be deleted?

    If you only have 1 circle at any time on the screen, then simply destroy it first and then spawn a new one.

    If you have many circles and need to delete only the last created instance, you can use a variable to store its UID.

    When you need to delete last instance, pick it by UID and destroy.

    When you spawn a new one, save its UID to that variable.

  • Hi dop2000 thanks for reply! At the moment there will only be two circles present in the screen, as the previous one should be deleted. I am not really good with coding and your suggestion seems complicated for me, but I will do my best to try that. Never thought of using a variable to store UID's.

  • It's simple. Create a global variable LastCircleUID.

    After you spawn a new circle do this:

    LastCircleUID=circle.UID

    When you need to delete a circle with this UID, do this:

    Pick circle with Unique ID : LastCircleUID

    circle -> Destroy

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • Thanks a lot dop2000! I will try this!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)