How can I destroy child object when parent object is destroyed?

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • Hey, for my game I'm using 2 active objects for each enemy. A parent object for the enemy and its values, and a child object for its animation.

    Now the issue I have with this is that I can't figure out how to destroy the child object when the parent object's health reaches 0. I mean, I can do 'Health of Parent = 0 -> Destroy Parent, Destroy Child', but then that destroys all versions of the child object (including the ones whose parent object still lives). I know that I need to add a condition that only applies to the specific enemy but I don't know how I could do this. Does anyone have an idea?

  • I'm not sure how fixed value is supposed to help here. If I understand correctly, a fixed value is a unique value that every object has. How does that allow me to destroy a specific object when an other specific object is destroyed?

    I also tried using spread value but that did not seem to work. Maybe I did it wrong. What I did was:

    Always
    - Parent: Spread value 1 in Alterable Value D
    - Child: Spread value 1 in Alterable Value A

    Alterable Value E of Child = Alterable Value D
    Health of Parent = 0
    - Destroy Child
    - Destroy Parent

    However, this seems to only destroy the parent objects.

  • Just give a look to this

    Hey KliK-iT, Nice example!

    I hope you don't mind, I changed it ever so slightly so that there is only one counter, and uses a fastloop to create new counters. It is attached.

    Please login to see this attachment.


    from this old post Please login to see this link.

    My game No God for Us Please login to see this link.

  • Well, I appreciate you trying to help me but that example simply doesn't have anything to do with what I need help with. I've got alterable values and healthbars working fine already. Maybe I wasn't clear, let me try to explain again.

    In my game, an enemy gets created every time the player takes X amount of steps.
    An enemy consists of 3 objects;
    1. Active object - Position, Alterable values, behavior etc (Parent object)
    2. Counter - Healthbar (Child object that follows the Parent object)
    3. Active object - Appearance and animation (Child object that follows the Parent object)
    When the Health (alterable value) of an enemy reaches 0, it is destroyed.
    When the value of a healthbar reaches 0, it is destroyed.

    However, how can I make it so the other active object (child object) is destroyed when its parent object is destroyed?

  • On creation you would stored the fixed value of the parent in an alterable value of the children. When the parent health value reaches 0, simply run a for each loop on each child object type and compare the fixed value of the parent to the fixed value stored in the child's alterable value and destroy it.

    Please login to see this link.

  • While Fusion do link objects together automatically, it's not really an exact science. So it's always a good idea to give them an ID so that you can refer to each individual object.

    Some things to keep in mind:

    Give child objects a reference Alterable Value to the parent.
    Remember to destroy the child object before destroying the parent.
    Use loops to deal with multiple overlapping objects.

    Take a look at the attached mfa.

  • Thanks for the tips. Though the issue is not resolved in the mfa that you attached? The child objects aren't getting destroyed, they're just getting moved to an other parent. They only get destroyed when the last parent is destroyed.

    However, keeping in mind to destroy the child before the parent, I deleted everything from my previous attempt and started over. Now I've got this:

    Every 5 seconds
    - Create Parent
    - Create Child
    - Parent: Set Alterable Value A (Health) to 100
    - Parent: Set Alterable Value B (ChildID) to Fixed value of Child

    Alterable Value A (ChildDead) of Child = 0
    - Set position at (0,0) from Parent

    Health of Parent <= 0
    Fixed value of Child = ChildID of Parent
    - Child: Set ChildDead to 1

    Health of Parent <= 0
    ChildDead of Child = 1
    - Destroy Child
    - Destroy Parent

    Now this should make the Child follow the Parent until the Parent's health is 0, then destroy the Child, and then destroy the Parent. This works fine when enemies are killed one by one, however when multiple enemies die at the same time, only one of the Child objects is destroyed, and the other ones are either teleported to an other Parent, or to 0,0 (until a new parent appears where they can get teleported to). This should not happen because the Child objects should only follow their Parent when their alterable value ChildDead is set to 0. This means that only one of the Child object's ChildDead value is being set to 1, while the others stay on 0. How can I fix this? Tried using loops but that didn't work, but maybe I did it wrong.

    Edited 2 times, last by Adnihil (December 20, 2016 at 2:30 PM).

  • I'm not seeing where the issue is here. You need to change the 'press spacebar' event to 'Always'. ForEach loops are now completely native so they are performing very optimally internally with the Fusion 2.5 engine. Change that event and it all works at it should. Ideally, when you see a possible situation that could arise you need to be constantly running the loop to ensure all objects and instances are iterated through accurately.

    Edit: Scratch that, I see your issue, I'll rework it now.

    Game Launcher Creator V3 - Please login to see this link.
    Bespoke Software Development - Please login to see this link.
    Learn Clickteam Fusion 2.5 - Please login to see this link.

    Danny // Clickteam

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!