by Jon (Updated on 2015-10-21)
Sometimes, you want an actor to act a little bit differently from the norm. Suppose that we’ve created a basic enemy for a Mario-like game, like a Goomba.
Now, we want to make a Hopping Goomba - one that jumps.
You could do this by creating a brand new Actor Type, copying everything about the regular Goomba, and adding a Jump behavior. But a few too many times and you end up with this...
Is there a better way to go about this? There is. It’s called Actor Customization.
Actor Customization is a feature that lets you tweak a specific instance of an Actor to behave differently.
To customize an Actor, left-click on the actor. Then click the Inspector Pane tab on the right hand side of the screen.
From this point, you can start customizing the actor in a few ways.
Click the + button in the Inspector to add a Behavior.
Doing so will bring up a dialog that lets you choose a Behavior to add, for example one that lets our Actor jump and run.
You can also remove a Behavior (for this Actor instance) from the Inspector by clicking the X button.
Suppose that we want a particular Actor to walk really quickly. We could increase the “Minimum Speed” field for the "Wander" Behavior that's already attached to this actor.
Recall that an Actor’s behaviors can’t directly refer to specific objects within a scene. This is why, when you attach a Behavior to an Actor, and that behavior has an Actor attribute, you see this.
Because an Actor’s behaviors are generic, they have no connections to specific scenes. In other words, there's no context for referring to things in specific scenes.
Is there a way to enter values into these fields for Actors? There is! Once you customize an actor, those Actor attribute fields can now let you pick out specific Actors and Regions within a scene.
I’ll explain how to do this through a common example: pressing switches.
Suppose that you're playing an adventure game like Zelda. You're inside a dungeon, and you come across a room with several switches. Stepping on a switch causes a particular door to open.
In a gist, we'll create a “Switch” behavior that, given a “Door” actor, will tell that Door actor to open up when our Hero steps (collides) on the switch. (The switch should also visually change to a pressed-down state)
Through Actor Customization, we can customize each instance of a switch, so each one will open up a particular door when pressed.
Note: As always, these explanations are for learning purposes. You’ll need to tweak the approach to fit your game's needs.
Download the Customizing Actors project. Import it using File > Import Game... and open it up.
Open the main scene.
Left-click the left switch (there are two switches total). Then, click the Inspector tab on the right. Click the Customize check box in the Inspector.
Notice that you now have full control over what behaviors are attached to this particular switch.
Click on Door Actor... in the Inspector - this will prompt you to choose the actor that this switch is connected to. Choose the left door.
Test the game. Step on the left switch. The left door will open.
You’ve customized the switches so that when the left/right switch is pressed, the left/right door opens.
How does this work? Let's take a peek into the "guts" of this sytem. Open up the Switch Behavior behavior.
The key piece is the Actor attribute called Door Actor. When you customized the Switch actor (via the Inspector pane), the "Door Actor" attribute let you pick a SPECIFIC door within the scene.
If you understand that connection, you now fully understand how Actor Customization works.