GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Destroy Child Actor

daniel.robert.campbelldaniel.robert.campbell Posts: 251Member
edited August 2016 in Working with GS (PC)

I need to create a parent/child relationship between two actors. At least that's what I THINK I need to do.

What I'm trying to accomplish:
I have a dozen actors running around my scene (parent). Each of them has a smaller actor (child) following them. When the Player Character makes contact with one of the (parent) actors, I want the (child) actor to be destroyed, but not the parent.

I know I could set up a variable for each parent to track and the child to check that variable on a regular basis to see if it needs to destroy itself. The problem with that; the final level of my game will have hundreds of these things running around.

Comments

  • tatiangtatiang Posts: 11,335Member, Sous Chef, PRO, Senior Sous-Chef

    Have each parent actor spawn a child actor in this fashion:
         Change attribute game.spawnNum to game.spawnNum+1
         Change attribute self.spawnNum to game.spawnNum
         Spawn Actor [child actor]

    Have each child actor set a value unique to its parent:
         Change attribute self.spawnNum to game.spawnNum

    When a parent actor is collided with:
         Change attribute game.deathNum to self.spawnNum

    Then, in the child actor have a rule that says:
         If self.spawnNum = game.deathNum
              Destroy actor

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • @tatiang said:
    Have each parent actor spawn a child actor in this fashion:
         Change attribute game.spawnNum to game.spawnNum+1
         Change attribute self.spawnNum to game.spawnNum
         Spawn Actor [child actor]

    Have each child actor set a value unique to its parent:
         Change attribute self.spawnNum to game.spawnNum

    When a parent actor is collided with:
         Change attribute game.deathNum to self.spawnNum

    Then, in the child actor have a rule that says:
         If self.spawnNum = game.deathNum
              Destroy actor

    I follow this up until I'm setting up the behavior where the parent has been collided with.

  • Wait, I think I've figured out what it is. When the parent spawns, it's assigning itself a number and saving it. The child is looking for that number to destroy itself. Wow! I never would have thought of that. Genius! Thank you so much!

  • tatiangtatiang Posts: 11,335Member, Sous Chef, PRO, Senior Sous-Chef

    Correct! You're welcome!

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • Only, I can't get it to work. :-( I'll keep banging away on it for a while to try and find out what I'm doing wrong and keep this thread updated.

    Quick question: Will this method still work if the Parent actors are already placed in the scene, and not being spawned by something?

  • tatiangtatiang Posts: 11,335Member, Sous Chef, PRO, Senior Sous-Chef

    @daniel.robert.campbell said:
    Quick question: Will this method still work if the Parent actors are already placed in the scene, and not being spawned by something?

    Yes, as long as the parent actors each spawn their own child actor.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Posts: 11,335Member, Sous Chef, PRO, Senior Sous-Chef
    edited August 2016

    Here's a demo. It was made with Mac Creator so you may need to Google convert mac gamesalad to windows to find out how to open it.

    https://www.dropbox.com/s/n5g3bxhzyfk56pn/Parent & Child.zip?dl=0

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • I've been working on this for most of the day, about 12 hours, and finally have it solved. There's absolutely nothing wrong with your method tating. It's flawless and actually pretty genius. You are definitely going into the "Special Thanks" assuming this game ever gets a release. That being said...the biggest issue wasn't with me, but with the GS client itself.

    Long Version:
    I finally got it working, but was the fault with my method? No... It was with the client's VERY poor messaging. I was clicking on the Parent actor in the scene viewer and adding the actor attributes in the "Actor" tab. Apparently when you do this, you're not actually adding the attribute to the prototype (even though the Backstage CLEARLY has the "Prototype" tab selected), you're making the change to the instance. Hell, the new behavior you set up is still even in the prototype...but not the attribute you're using in it. How do I know? If you delete all instances of the actor from the scene, and then reselect the prototype, the attribute is now "invalid". To get this to work I had to delete all instances of the actor from the scene, make the changes I wanted, then re-add all the instances. I think the biggest issue isn't so much the fact that it does this, but more the fact that it doesn't clearly tell you that you're making changes to the instance rather than the prototype. It's even more confusing by the fact that when you're selecting the instance, the "prototype tab" is still highlighted on the backstage, as if you're editing the properties of the prototype. Now in GS's defense it does say on the Actor tab that you're editing the instance but it's a VERY small font that's VERY easy to miss. They should likely add that giant "Lock" icon over the window so it's SUPER clear that you're only changing the instance.

    Short Version:
    If you're going to make changes to an actor in GS Windows, make sure you're selecting the actor via the "Actors" tab in the viewer, and under the "All" section. Otherwise the client is likely going to cause you a MASSIVE headache later. Hopefully GS will eventually put a giant "Lock" icon over the actor tab like they did when viewing the backstage of an actor instance, but for now just try and remember NOT to trust selecting an actor from the scene viewer.

  • @tatiang said:

    @daniel.robert.campbell said:
    Quick question: Will this method still work if the Parent actors are already placed in the scene, and not being spawned by something?

    Yes, as long as the parent actors each spawn their own child actor.

    Thanks a ton for putting this together.

    PS: Windows can open up Mac projects without any kind of conversion needed. Just find the project file and you're good to go.

  • Also, Hopefully GS ends up making a simple way of pulling this off in the future. Maybe an event that listens for "if (ActorX) collides with (ActorY), do: [THIS]"

  • tatiangtatiang Posts: 11,335Member, Sous Chef, PRO, Senior Sous-Chef

    @daniel.robert.campbell said:
    PS: Windows can open up Mac projects without any kind of conversion needed. Just find the project file and you're good to go.

    Ah, good to know!

    @daniel.robert.campbell said:
    Also, Hopefully GS ends up making a simple way of pulling this off in the future. Maybe an event that listens for "if (ActorX) collides with (ActorY), do: [THIS]"

    It would be handy to have that for Actor Z, for sure.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Sign In or Register to comment.