Skip to content

Actor from code

An Actor is a character in the game: a person with a name, an age, a family, a clan and a mind. Your code gets one from IM.ActorDictionary, from IM.Actors, from IM.Player, or from a component in the scene, since Actor is a MonoBehaviour. This page lists the members you use on it.

You hold an Actor and want to read or change something about it. Start with the group that fits. The first sentence of each row tells you what the call does. Writers on this page change the world, so on a multiplayer client they are refused with one warning. Read the Scripting overview for that rule.

All files are in Runtime/Actors/.

Member What it does File
string ID The unique ID. Actor.cs
string Name The name. Actor.cs
string FullName The name built from the Full Name Format of the actor’s culture. Actor.cs
bool IsPlayer True when a human plays this actor, here or on another machine. Actor.cs
LifeState State Alive or Dead. Actor.State.cs
int Age The age in years. Actor.State.cs
GenderType Gender Male or Female. Actor.State.cs
Culture Culture The culture. Actor.State.cs
bool Inheritor Whether the actor can inherit. Actor.State.cs
AgeGroup AgeGroup The age group of the actor’s age, or null for none. Actor.State.cs
Member What it does File
void SetState(LifeState state, bool noninheritor = false) Kills or revives the actor. A death runs succession, turns marriages into widowhoods and removes a dead accomplice from its schemes. With noninheritor the seat does not pass on. Actor.State.cs
void SetAge(int age) Sets the age, kept within 0 and IM.OldestAge, with no upper end when OldestAge is 0. Nothing happens when the age stays the same. Actor.State.cs
void SetName(string name) Renames the actor. Nothing happens when the name stays the same. Actor.State.cs
void SetCulture(string cultureNameOrId), SetCulture(Culture culture) Changes the culture. An unknown name changes nothing. Actor.State.cs
void SetCulture(Culture culture, bool refitLook) The same, and gives the actor a look that fits the new culture. Actor.State.cs
void SetInheritor(bool inheritor) Sets whether the actor can be an inheritor. Actor.State.cs

SetState is the call with the most consequences. A death raises IM.onActorDeath, then runs succession, then the actor’s own onActorDeath, then turns marriages into widowhoods, then removes a dead accomplice from its schemes, then sends the state notification.

The relative methods come in two shapes. The first returns a collection, and takes inclusivePassive, which says whether dead relatives are included. Each is IEnumerable<Actor>: Parents, Children, Spouses, Grandparents, Grandchildren, Siblings, Nephews, Nieces, Uncles, Aunts, BrothersInLaw, SistersInLaw.

For checks and loops use the second shape, which allocates nothing and is main thread only.

Member What it does File
void GetRelatives(FamilyRelation relation, List<Actor> results, bool includeDead = true) Fills results (cleared first), each relative once. Actor.Family.cs
bool IsRelation(FamilyRelation relation, Actor other, bool includeDead = true) True when other is the actor’s relative of that kind. Actor.Family.cs
bool HasRelative(FamilyRelation relation, bool includeDead = false) True when at least one relative of that kind exists. Only living ones count by default. Actor.Family.cs
int CountRelatives(FamilyRelation relation, bool includeDead = true) How many relatives of that kind. Actor.Family.cs
Family Family, Family BirthFamily The family the actor belongs to, and the one it was born into. A wedding never changes the second. Actor.Family.cs
bool JoinFamily(Family family, bool setOrigin = false), bool QuitFamily(bool forgetOrigin = false) Moves the actor into a family, or out of its family. Actor.Family.cs

FamilyRelation has twelve values: Parent, Child, Spouse, Grandparent, Grandchild, Sibling, Nephew, Niece, Uncle, Aunt, BrotherInLaw, SisterInLaw (Actors/FamilyRelation.cs). Shortcut properties and methods exist for each: HasChildren, HasParent, IsSibling(Actor) and the rest of that pattern.

Example, not compiled. It lists the living children of an actor.

var children = new List<Actor>();
actor.GetRelatives(FamilyRelation.Child, children, includeDead: false);
Member What it does
Marriage Marry(Actor spouse, MarriageTerms terms = default) Marries the two. Returns null when refused.
bool CanMarry(Actor spouse), bool CanMarry(Actor spouse, out MarriageCheck check) True when the wedding would be allowed. check says why not.
bool Divorce(Actor spouse, DivorceTerms terms = default), int DivorceAll(DivorceTerms terms = default) Ends one marriage, or every living one.
Actor HaveChild(Actor otherParent = null, ChildOptions options = null) A new runtime actor is born. Returns null when refused.
bool AddChild(Actor child, bool joinFamily = true, bool setOrigin = true) Makes an existing actor a child of this actor.
Actor Spouse, int SpouseCount, bool IsMarried, bool IsWidowed, MaritalStatus MaritalStatus, IReadOnlyList<Marriage> Marriages The marriage state.

All of these are in Actor.Family.cs. The marriage types and the hooks are on Families and marriage from code.

Example, copied from the demo project (Game/Rules/RulesPeople.cs, lines 143 and 149). A suitor is collected when the wedding is allowed, and the chosen one is married.

if (woman.CanMarry(man, out var check)) suitors.Add(man);
// ...
if (woman.Marry(husband) != null)
Member What it does File
Clan Clan The clan the actor belongs to. Actor.Clan.cs
void JoinClan(Clan clan), void JoinClan(string clanNameOrId) Joins a clan. A court role is a seat of the clan, so the actor joins without one. Actor.Clan.cs
void QuitClan() Leaves the clan. The court role stays with the clan. The personal role is kept. Actor.Clan.cs
bool HasPolicy(string policyNameOrId) True when the actor’s clan or family has the policy. Actor.Clan.cs
Role Role The court role, a seat in the clan’s court. Actor.Roles.cs
Role PersonalRole The personal role, a calling such as Doctor. null for none. Actor.Roles.cs
string Title, string PersonalTitle The title of the court role (else the personal role) for the actor’s gender. Actor.Roles.cs
bool SetRole(string roleNameOrId), bool SetRole(Role role) A court role needs a free seat in the actor’s clan. A personal role is always given. Actor.Roles.cs
bool HasRole(string roleNameOrId) True for a court or a personal role. Actor.Roles.cs
void RoleDismiss(), void RoleDismiss(RoleKind kind) Removes the court role, or the role of the kind you name. The seat raises IM.onRoleVacant. Actor.Roles.cs

To replace a holder when every seat is taken, use Clan.Appoint. It is on Clans, roles and succession from code.

Member What it does File
Actor Heir Who would inherit the actor’s seat now. Main thread only. Actor.Heir.cs
Actor Successor Who inherited this actor’s seat. Actor.Heir.cs
void SetHeir(Actor actor) Chooses the heir of the court seat. null goes back to the rule alone. Actor.Heir.cs
bool HeirOverridden True when the actor chose an heir with SetHeir. Actor.Heir.cs
int GetLineOfSuccession(List<HeirCandidate> results, int max = 10) Fills results with the people who would inherit, first to last. Actor.Heir.cs
Actor PersonalHeir The first in line for the personal role. Actor.Heir.cs
bool Abdicate(out Actor heir) Steps down and passes the seat to the heir at once. false and the actor keeps the role when nobody is in line. Actor.Heir.cs

Traits, modifiers, opinions, memories, ties and ambitions are on the actor too. The main calls:

Member What it does
IReadOnlyList<Trait> Traits, bool HasTrait(string), bool AddTrait(string), bool RemoveTrait(string) Traits. A trait adds its changes to the actor’s variables at once.
bool AddModifier(string variableNameOrId, double amount, int days = 0, string name = null) A modifier on an Integer or Float variable.
float OpinionOf(Actor other) What this actor thinks of other.
bool Remember(string memoryKindNameOrId, Actor about, float percent = 100f), int Forget(string memoryKindNameOrId = null, Actor about = null) Memories.
bool AddTie(string tieKindNameOrId, Actor with), int RemoveTie(...), bool HasTie(...) Ties.
bool SetAmbition(string ambitionNameOrId, Actor about = null), int ClearAmbition(...), bool HasAmbition(...) Ambitions.

All are in Actor.Mind.cs. Behaviour from code covers them with the rest of the mind.

Member What it does File
ActorLook Look The actor’s look, or null. Actor.State.cs
Sprite Portrait The picture the actor shows for its age group and state. Actor.State.cs
void SetLook(ActorLook value), void SetLook(string nameOrId) Gives the actor a look. An unknown name changes nothing. Actor.State.cs
void SetPortrait(Sprite portrait) Gives the actor the look of a picture. Actor.State.cs
bool RefreshLook(bool refit = false) Gives the actor a look that fits when it has none or has outgrown it. Actor.State.cs
  • Schemes: StartScheme, RequestScheme, GetSchemesFor, SchemeIsActive, GetScheme. They are on Schemes from code.
  • Variables: Variables, GetVariable, SetVariable, AddVariable and the relationship calls, in Actor.Variables.cs. They are on Variables from code.
  • Events on the actor: onSchemeStarted, onSchemeEnded, onJoinedClan, onLeftClan, onRoleChanged, onActorIsMarried, onActorDivorced, onChildBorn, onAgeChanged and more, in Actor.Events.cs. The list is on Events reference.
  • Away from the scene: bool IsAway and string AwayFrom (Actor.Home.cs) say whether a parked actor left its scene, and which one.
What you see Why What to do
Marry returns null The world’s rules, FamilyLaw.CanMarry or a missing spouse refused it. Call CanMarry(spouse, out var check) and read check.Text.
SetRole returns false Every seat of that court role in the actor’s clan is taken. Use Clan.Appoint(actor, role, replace: true).
Heir is null Nobody is in line: the actor has no clan or no role, the role is not inherited, or nobody may inherit. Read Role.Inheritance, then GetLineOfSuccession.
AddTrait returns false The trait is not in the game, the actor has it, the trait is earned (the game gives those), a group rule holds an earned trait of the group, or the call ran off the host. Check the name and the machine.
A writer logs one warning and does nothing A multiplayer client called it. Call it on the host.