Smashed
This page uses Vector3 from Unity. The glossary says what each one is.
Some objects spawn an item when a hit uses up their health. They are not breakables, so Broken never fires for them and Smashed never fires for a breakable. Smashed tells you about the hit and what the object would drop.
Breakables smashable objects
Listen to Smashed to hear when a hit destroys an object that drops an item. The event only reports what happened, and you cannot change the outcome.
public static class Breakables
{
public static event Action<SmashedArgs> Smashed;
}
| Event | Gives you | When it fires |
|---|---|---|
Smashed | SmashedArgs | A smashable object has just been destroyed by a hit. |
SmashedArgs what Smashed tells you
Smashed hands you this. SpawnItemId is the item it drops, or -1 when it drops none, and IsAnimal says whether it was an animal.
public sealed class SmashedArgs
{
public string Id { get; }
public Vector3 Position { get; }
public bool IsAnimal { get; }
public int SpawnItemId { get; }
}
| Property | Type | What it means |
|---|---|---|
Id | string | The object’s id: its saved number, or a scene path when it has none. |
Position | Vector3 | Where the object was, in world coordinates, just before it broke. |
IsAnimal | bool | true when the object is an animal rather than a thing. |
SpawnItemId | int | The id of the item it drops. -1 when it drops no item. |
Things to know
Smashedfires when a hit takes the object’s health from above 0 to 0 or less. A hit the object does not accept does not fire it. (The check isCheckDamageType(type) && health - damage <= 0, made before the game’sDamageruns. An object’sallowedDamageTypesdecide which hits count.)- An object that is not removed after it is smashed fires
Smashedagain on every later hit. The game keeps running its break code each time, and drops its item again each time. If your mod counts smashes, remember theIdof each one you have already seen. (Whilehealthstays 0 or less, the game takes its break branch on every hit and re-spawns the loot.) - An animal that dies also fires
Smashed. The game kills an animal through the same code path, so you can tell it apart byIsAnimal. (Destroy(), whichAnimalStatscalls when an animal dies, goes throughSpawnItemOnBreak.Damage.) - The object may already be gone when your handler runs, so read the values in
SmashedArgsand not the object. The values were taken just before the break. (The event runs as a Harmony postfix, after the game’s break code, so the object may already be destroyed.) SpawnItemIdis-1when the object drops nothing. That includes an item with id 0. (It isitemToSpawn.Item.ID, or -1 whenitemToSpawnor itsItemis null or theIDis 0.)
Limits
Smasheddoes not fire while a save is loading.Smashedonly tells you what happened, and you can’t change it. You cannot cancel the break, change what drops, or change the crime record or a save through this event.