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 calls BreakableLock.Break with the lock’s remaining strength as damage and DamageReceiver.DamageType.Any.)
  • Read Strength to see whether a lock is broken, not Locked. Breaking a lock does not turn Locked off, so a broken lock can still say Locked is true. The game disables a broken lock’s collision and interaction, so the player cannot use it. (BreakableLock.Break never sets _Lock.Locked. UpdateModel disables the lock’s collider and interaction.)
  • LockBroken fires once, when a hit takes a lock’s strength from above 0 to 0 or less. Its BreakableArgs.Id is 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 with FindObjectsByType and skips inactive objects. A lock’s id is made the same way as a breakable’s id.)
  • BreakLock(id) returns false when no lock has that id, when the lock is already broken, or when a save is loading or being written. It returns true when the lock is broken afterwards.
  • LockBroken does 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’s Unlocked, which sets the strength to 0 without a break. A hit that the lock’s allowed damage types refuse does not change its strength.)