Locks
A lock can break when it is hit hard enough. A lock is not a breakable: it is a different kind of object, so Broken and Repaired never fire for it. Use Locks(), BreakLock and LockBroken for locks. There is no call to repair a lock.
Breakables break locks
Use Locks to list the locks in the scene and BreakLock to break one by its id. LockBroken tells you when a hit breaks one.
public static class Breakables
{
public static List<BreakableLockInfo> Locks();
public static bool BreakLock(string id);
public static event Action<BreakableArgs> LockBroken;
}
| Method | Returns | What it does |
|---|---|---|
Locks() | List<BreakableLockInfo> | Every lock in the scene the player is in. |
BreakLock(id) | bool | Breaks a lock. true when it is broken afterwards. |
| Event | Gives you | When it fires |
|---|---|---|
LockBroken | BreakableArgs | A lock has just broken. |
BreakableLockInfo a snapshot of one lock
Locks gives you one of these for each lock. Use Strength to see whether it is broken, because Locked does not change when a lock breaks.
public sealed class BreakableLockInfo
{
public string Id { get; }
public bool Locked { get; }
public int Strength { get; }
}
| Property | Type | What it means |
|---|---|---|
Id | string | The id to pass to BreakLock. |
Locked | bool | The game’s lock state. Breaking a lock does not change it. |
Strength | int | How strong the lock is. 0 or less once it is broken. |
Things to know
BreakLock(id)breaks the lock the way a hit would. (It callsBreakableLock.Breakwith the lock’s remaining strength as damage andDamageReceiver.DamageType.Any.)- Read
Strengthto see whether a lock is broken, notLocked. Breaking a lock does not turnLockedoff, so a broken lock can still sayLockedistrue. The game disables a broken lock’s collision and interaction, so the player cannot use it. (BreakableLock.Breaknever sets_Lock.Locked.UpdateModeldisables the lock’s collider and interaction.) LockBrokenfires once, when a hit takes a lock’s strength from above 0 to 0 or less. ItsBreakableArgs.Idis the lock’s id.
Limits
Locks()only lists locks that are switched on in the scene the player is in. A lock that is switched off is skipped. (It searches the active scene withFindObjectsByTypeand skips inactive objects. A lock’s id is made the same way as a breakable’s id.)BreakLock(id)returnsfalsewhen no lock has that id, when the lock is already broken, or when a save is loading or being written. It returnstruewhen the lock is broken afterwards.LockBrokendoes not fire while a save is loading, when a key or a lockpick opens the lock, or for a hit the lock does not accept. (A key or lockpick unlock goes through the game’sUnlocked, which sets the strength to 0 without a break. A hit that the lock’s allowed damage types refuse does not change its strength.)