Orders
This page uses Transform from Unity. The glossary says what each one is.
This is the full list of what the API gives you. All orders are in one static class. modId is your mod’s id (see Mod id). animalId is the Id of an AnimalInfo from Animals.All().
AnimalActions orders for animals
Each order takes your mod id and the Id of an animal from Animals.All(), and returns false when the game refuses it.
public static class AnimalActions
{
public static bool Sit(string modId, int animalId);
public static bool Sleep(string modId, int animalId);
public static bool SleepPermanently(string modId, int animalId);
public static bool Hunt(string modId, int animalId, Transform target);
public static bool StopHunt(string modId, int animalId);
public static bool Clear(string modId);
public static bool Run(string modId, int animalId, float seconds);
public static bool SetTame(string modId, int animalId, bool tame);
}
| Method | Returns | What it does |
|---|---|---|
Sit(modId, animalId) | bool | The animal sits down for a while. |
Sleep(modId, animalId) | bool | The animal sleeps until the game wakes it. |
SleepPermanently(modId, animalId) | bool | The animal sleeps until your mod lets it go. |
Hunt(modId, animalId, target) | bool | The animal goes after the target. |
StopHunt(modId, animalId) | bool | The animal gives up its hunt and picks a new place to go. |
Clear(modId) | bool | Lets go of everything your mod holds on animals. |
Run(modId, animalId, seconds) | bool | The animal runs for this many seconds. |
SetTame(modId, animalId, tame) | bool | true makes the animal tame, false makes it wild. |
Things to know
- An order only works on an animal that is in the scene you are in and switched on. An unknown id, an animal that is switched off, or a call made while a save is loading or being written returns
false. (The animal is looked up among the active scene’sAnimalcomponents byGetInstanceID, andSaveGate.Busy(true while a save loads or is written) blocks the call.) - Pass a valid mod id. A mod id is 1 to 64 letters, digits, dots, underscores or hyphens. Anything else throws an
ArgumentException. - Every other problem returns
falseand never throws. A bad value or a game failure gives youfalse, and the first failure of each order goes to the log as an error. Sitmakes the animal sit. The game ends the sit on its own timer, then the animal walks again.Sleepputs the animal to sleep for the game’s own sleep time. It returnsfalsefor an animal that a mod is keeping asleep withSleepPermanently.SleepPermanentlyputs the animal to sleep with no timer, and your mod keeps it asleep until you callClearor a new level loads. It returnstruefor a live animal. Calling it twice from the same mod keeps one hold, not two. (It callsAnimal.Sleep(true). The framework reads the privateAnimal.currentStatebefore it acts on a hold, and an animal that is awake loses its holds.ClearcallsAnimal.OnSleepingDoneonly for an animal that is still asleep.)Huntmakes the animal go aftertarget, and returnstrueonly when the animal is now really chasing it. The target needs a health component (Stats) on it or on a child. (It callsAnimal.HuntTargetand returnstruewhenAnimal.CurrentTarget()is thatStatscomponent afterwards.)StopHuntends the animal’s hunt and makes it pick a new place to go. It returnstruefor a live animal. (It callsAnimal.BreakOffHunt.)Runmakes the animal run forseconds.secondsmust be a real number above0, otherwise you getfalse. The game’s own cooldown ends the run.Clear(modId)lets go of everything your mod holds on animals. It ends every hunt your mod started withHunt(if the animal is still chasing that target), wakes every animal your mod keeps asleep (if it is still asleep), and forgets the tame choices your mod saved withSetTame. It returnsfalsewhen your mod had nothing to let go of. While a save is loading or being written, it returnsfalseand ends nothing if your mod has saved tame choices.- A new level load ends the holds of every mod. When the game loads a new level in place of the current one, every hunt and every permanent sleep from every mod ends. When the game loads a neighbouring level in the background, which it does ahead of time, nothing ends. (The framework ends them on a
LoadSceneMode.Singleload. An additive load does not end them.)
Limits
- The game may refuse a
Hunt, for example while the animal is avoiding an obstacle or is not hungry enough, and then you getfalse. The game ends the hunt by its own rules. - The hold from
SleepPermanentlyis best effort. The game can wake an animal that gets hurt, and its own sleep and sit timers can also end the sleep. When that happens, your hold ends by itself. - While a mod keeps an animal asleep,
Sit,Sleep,Hunt,StopHuntandRunreturnfalsefor that animal. - If another mod also has a hunt or a permanent sleep on the same animal, the animal keeps that when your mod calls
Clear.