Skip to content

Other extension points

Most of what you change in Intrigues you change in the Studio. These four places take code instead. Each one is a hook the package asks while it works, and each one is small: a delegate, an event, or an interface.

  • Heirs must follow a rule the Studio cannot express.
  • Some marriages, divorces or births must be refused by your game.
  • Your scene should react when a scheme sends a signal, or your code should send one.
  • Your project does not use the old Input Manager.

A Play session clears every hook. Add them from a component, or from a method marked [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)] or later. Everything here runs on the main thread. (sources: Succession.cs, FamilyLaw.cs)

Succession is a static class in MrW.Intrigues. Its hooks go from light to heavy, as its own documentation orders them:

  1. Actor.SetHeir: the holder names an heir (court role).
  2. Succession.CanInherit: refuse some people.
  3. A rule of kind Decided in code plus Succession.Register: your code names the whole line.
  4. An IM.onRoleVacant listener that appoints someone with Clan.Appoint, or calls Succession.Fill.
  5. Override Actor.OnActorDeath.
Member What it does
event Func<Actor, Role, Actor, bool> CanInherit Asked for every person who could inherit: holder, role, candidate. A listener that returns false refuses the candidate, who keeps their place for their children. The log records a listener that throws, and it does not refuse.
delegate SuccessionMethod(Actor holder, Role role, Clan clan, List<Actor> line) Fill line with the people who should inherit, first to last. The engine drops dead people, duplicates and the holder afterwards.
Register(string method, SuccessionMethod pick) Gives a rule of kind Decided in code its method. Registering a name again replaces the method.
Unregister(string method) Removes it.
Refresh() Works every heir out again on its next read. Call it after something the package cannot see changed, such as a field of a live rule.
GetLine(holder, results, max) Fills a List<HeirCandidate> with the people who would inherit, first to last. Also with a Role.
Explain(holder, results) Fills a List<HeirCandidate> with the people in the line and the people passed over, each with the reason. Also with a Role.
Fill(clan, role, previousHolder) Fills an empty seat from the previous holder’s line. False when there is no free place, no inherited role, or nobody in line. Refused on a client.
RuleFor(clan, role) The rule that decides who inherits.
Version Changes whenever any heir may have changed.

To use a method, set the rule’s kind to Decided in code in the Studio and type the name in the field Method name. The same name goes into Register. The Studio reports “Enter the name of the method that decides the heir.” while that field is empty. (source: SuccessionFields.cs)

CanInherit listeners must be cheap and free of side effects. The package asks them whenever it works out a line, for menus and tooltips as well as when a role passes on. Call Refresh() when what a listener reads changes.

Example. Compiled against the package’s runtime assembly; not run in Unity. A method and a veto, built from the signatures above.

using System.Collections.Generic;
using MrW.Intrigues;
using UnityEngine;
public static class MyRules
{
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)]
private static void Install()
{
Succession.Register("Elders Vote", ElderVote);
Succession.CanInherit += MayInherit;
}
private static void ElderVote(Actor holder, Role role, Clan clan, List<Actor> line)
{
// Add the people who should inherit, first to last.
}
private static bool MayInherit(Actor holder, Role role, Actor candidate)
{
return true; // Return false to refuse this candidate.
}
}

See Clans, roles and succession for how a rule is set in the Studio.

FamilyLaw holds the rules of marriage, divorce and birth in the running game, plus the hooks through which your code may refuse or decide.

Member What it does
Rules The world’s FamilyRules. Change its fields to change the rules; marriages that exist stay.
event Func<Actor, Actor, bool> CanMarry Asked before a wedding, after the world’s rules allowed it. Arguments: the actor the wedding is called on, the spouse. Any listener that returns false refuses it.
event Func<Actor, Actor, bool> CanDivorce Asked before a divorce. Same arguments.
event Func<Actor, Actor, bool> CanHaveChild Asked before a birth, and before an existing actor becomes a child. Arguments: the parent, the other parent (may be null).
Func<Actor, Actor, Actor> DecideHome A field, not an event. Decides who is home in a wedding “as the customs say”: return one of the two, or null to let the customs decide. Not asked when the terms name the home.
Check(actor, spouse) Whether the two may marry now, and if not, why and because of whom (MarriageCheck).
RulesFor(actor, spouse), RulesFor(marriage), RulesForChild(parent, otherParent) Which rule set applies. Read only.
HomeOf(...), FamilyOfChild(...) The partner who would be home; the family a child would be born into.

A hook that throws goes to the log and counts as “no objection”. A hook that starts another check inside itself gets asked again at most 4 levels deep. Check runs on the main thread only; from another thread it logs an error and returns a refusal. (source: FamilyLaw.cs)

Example. Compiled against the package’s runtime assembly; not run in Unity.

FamilyLaw.CanMarry += (actor, spouse) =>
{
return true; // Return false to refuse this wedding.
};

See Families and marriage.

A scheme sends a signal with a Send Signal node. Code can send and receive them too. See Signals for the scheme side.

Member What it does
IM.Signal(Signal signal) Sends a signal with no actors. A null signal logs a warning and sends nothing.
IM.Signal(Signal signal, Actor conspirator, Actor target, Scheme scheme = null) Sends it with the actors and scheme that sent it.
event Action<Signal> IM.onSignalReceive Raised on the main thread when a signal is sent. Listeners run in the order they subscribed. One that throws goes to the log and does not stop the others.
IM.CurrentSignal A SignalContext for the signal being handled.
SignalContext Signal, Conspirator, Target, Scheme, and IsSet, false outside a signal. Conspirator, Target and Scheme are null when code sent the signal without them.

SignalReceiver is the component behind the inspector. From code it offers Reactions, IsListening, AddReaction(Signal, UnityAction), RemoveReaction, RemoveReactions(signal), ReactsTo(signal) and Receive(signal). Receive runs every reaction to a signal; it does not check enabled and does not set IM.CurrentSignal.

Signals nest at most 16 deep. A deeper one gets an error in the log and no delivery, and so does a send from another thread. On a machine that is not the host, IM.Signal goes to the host; without a way to send it there, the call is refused. (sources: IM.Signals.cs, SignalReceiver.cs)

Intrigues reads keys and the pointer through one interface, IIntrigueInput in the namespace MrW.Intrigues.UI, so you can plug in the input system you use.

Member What it does
IIntrigueInput.AnyKeyDown True in the frame any key or button went down.
GetKeyDown(KeyCode), GetKeyUp(KeyCode), GetKey(KeyCode) Went down, was released, is held.
PointerPosition Screen pixels, origin bottom left.
Available False when no device can be read; the package then does nothing with input.
IIntrigueInputExtras Optional: GetMouseButton, GetMouseButtonDown, GetMouseButtonUp, ScrollDelta, VerticalAxis. Without it, mouse buttons are read through your GetKey with KeyCode.Mouse0 plus the button number, and the wheel and the axis read zero.
IntrigueInput.Provider The provider in use. Set it to yours; set null to bring back the default.

The default reads the legacy Input Manager. In a project that uses only the new Input System, it reads that through the optional assembly MrW.Intrigues.InputSystem, present when the package com.unity.inputsystem 1.7 or newer is. Without it, nothing is read and the log gets one warning. Play mode clears the provider, and it is not saved. Set it in an Awake of your own in every session. (source: IntrigueInput.cs)

You need a provider of your own only for another input system. The XML documentation of IntrigueInput has a full example provider for the new Input System. Copy it from there; its key mapping is left for you to write.

What you see Why What to do
Your hook never runs after you press Play. Play clears hooks when it starts. Add them from a component, or from AfterAssembliesLoaded or later.
The Console says the role is decided in code by a method, “but no method of that name is registered, so nobody inherits”. No Register call ran with that name. Call Succession.Register with the same text when the game starts.
The menus feel slow after you add CanInherit. The package asks it whenever a line is shown. Keep it cheap.
“IM.Signal was called from a background thread.” A send off the main thread. Send from the main thread.