Creating and Destroying Actors
by Jon (Updated on 2015-10-20)
- Creating Actors
- Referring to the "Last Created Actor"
- Destroying Actors
Use the create-actor-of-type block (under Scene > Actors).
You can drag an actor-type block into the Choose Actor Type field. This is useful when you want to make this field configurable.
Front / Middle / Back will place the actor on those layers, respetively. Middle will choose whatever layer is closest to the middle. If you need a specific layer, change the actor's layer after creation.
- In terms of execution order, when you create an actor, the new actor's "when created" event is run before the current behavior proceeds further.
Referring to the "Last Created Actor"
Sometimes, you’ll want to refer to the actor that you just created. Use the “last created actor” option under any Actor dropdown to do this.
Destroying actors is similar to creating them. Use the kill-actor block (under Scene > Actors).
Killing an actor is immediate. Don’t attempt to refer to an actor at any point after you’ve killed it. Especially during timed tasks (do-after, do-every), where it's easy for this to happen by accident.
Events: Knowing when actors get created or die
We provide events that let you control what happens when an actor is created or destroyed. Select one of these events via the “Add Event” button.
- When an actor dies, the die event happens before the actor actually dies, so you can still refer to it during the event.
- When an actor is created, the actor's "when created" event always runs first. Then, the other created events pertaining to the actor are run.
Challenge 1: Create A Particle Effect
Why not try creating a particle effect using lightweight actors (or images) and along the way, compare its performance to doing this with regular actors?
To create particle effects, just spawn actors rapidly and “emit” them at a random speed and starting position and have them fade out over time. With some experimentation, you can create a fire and smoke effect with ease.
Challenge 2: Create A Bullet Limiter
Many games have a mechanic that allows you to fire bullets, but only a certain number at a time, otherwise the game would become too easy.
Why not try creating a bullet limiter that allows the player to create no more than 3 bullets at once?
Print Article Edit Article How to Edit an Article
Hint: Use the ‘when an actor of [TYPE] is created/killed’ event.
Very weak metaphor.
I understand what you mean zhaetur. Being recycled and having more numbers has always come to thought as being superior. To answer your question try to think of WWII. In History class I'm assuming that you always had the assumption that the Germans would stand no chance against the Russians. Think about it, the Russians have hugeee amount of numbers, but thats it. They didnt have supplies, special ammo, updated guns and their men werent trained that well. The Germans had all of that. The Germans would of beat the Russians if it hadnt of been for the Russian winters. So what I'm saying is is that being large in supply of men does not make you superior and especially when they are only computerized, they frequently are recycled so they have no means of skills or experience.
It sounds like recycled actors are superior to created actors, when are created actors superior?