Let the player play another character
Goal: the player’s character dies or changes, and the player carries on as someone else, usually the heir.
With a node
Section titled “With a node”- Add a Switch Player node where the switch should happen, for example after the death of the character.
- Set Whose Player. Whoever plays an actor is the default of a new node. Then set Whoever Plays to the actor whose player moves, for example the Target. This machine’s player means the person at this computer.
- Set Play As. An actor lets you pick the Actor to continue as. The player’s heir takes the first in line for the court role of the actor played now. The player’s personal heir takes the first in line for the personal role.
- Leave Only If Alive on to refuse a dead actor.
- Wire Switched to what comes next, and Not Switched to a sensible fallback.
You will see: the flow continues through Switched and the player now plays the new actor. Schemes already running keep their Conspirator.
If Whoever Plays cannot be found, the node stops without either output. Not Switched runs when nobody plays the chosen actor, when the new actor is not available or has no heir, or, with Only If Alive on, when the new actor is dead.
The demo’s system scheme Inheritance Proclamation has a Switch Player node that uses Whoever plays an actor with the Target and An actor with the Conspirator. Heirs come from the roles; see Choose who inherits.
From code
Section titled “From code”Example. Compiled against the package’s runtime assembly; not run in Unity. The two signatures are from IM.Players.cs:
IM.SetPlayer(newActor); // this machine's playerIM.MovePlayer(oldActor, newActor); // whoever plays oldActor| Signature | What it does |
|---|---|
static void SetPlayer(Actor actor) |
Makes the actor this machine’s player. null means nobody. The old player loses the player mark. An actor not registered with the manager is refused, with a note at Log level. |
static bool MovePlayer(Actor from, Actor to) |
The human who plays from plays to from now on, on any machine. Returns false when nobody plays from, when another human plays to, for a null actor, and on a multiplayer client. |
Listen to IM.onPlayerIsChanged (old and new player) if your interface follows the player. See IM in code.
What can go wrong
Section titled “What can go wrong”- The flow stops with “Play As: no actor is chosen”: Play As is An actor and Actor is empty.
- Nothing changes in a multiplayer game when a client runs the call: only the host moves players. See Seats.
- Your own interface still shows the old character:
SetPlayerchanges who plays and raisesonPlayerIsChanged. Your interface has to listen to it.