Puzzle System


This is the core class for the Logic elements. This means that the subclasses of this component also have all properties and methods that are present in here. Make use of it.


As soon as you add the component to the game object, you will need to assign a few fields in the inspector view.
The first field is an array of all triggers that are related to the system.
Make sure to manually assign all triggers related to the puzzle to this array, unless you created the system using the editor utility tool.
Two other properties define the auto resets of the system when the puzzle is solved or failed. In other words, whether or not the puzzle needs to reset all triggers and the logic system in these cases.
There are a few public readonly properties that can be accessed from outside of the component/system:
  • bool IsSolved -- is the puzzle in the solved state?
  • bool IsFailed -- is the puzzle in the failed state?
  • bool IsAutoResetSolution -- will the puzzle be auto reset on solved?
  • bool IsAutoResetFailure -- will the puzzle be auto reset on failure?
There are a few public methods that you can also makes use of:
/// <summary>
/// Forces the solve of the puzzle.
/// </summary>
public void ForceSolve();
/// <summary>
/// Forces the fail of the puzzle.
/// </summary>
/// <param name="immediate">If set to <c>true</c>, resets the puzzle's elements immediately, regardless of internal implementations.</param>
public void ForceFail(bool immediate = true);
/// <summary>
/// Links the triggers for the system.
/// </summary>
/// <param name="newTriggers">New triggers.</param>
public void SetTriggers(CorePuzzleTrigger[] newTriggers);


Unlike the CorePuzzleHandler, this class more likely needs to be extended. By default, it has a very simple logic. In order to solve it, the player must just activate all triggers.
By inheriting this class, you will get access to a few useful protected fields:
  • CorePuzzleHandler handler -- the reference to the handler entity.
  • int completedSteps -- the count of the successfuly completed steps. It might be used for comparing it to a total number of triggers, and if they are equal, the puzzle is solved.
There are multiple methods that can be overridden:
/// <summary>
/// A standard Unity awake function. By default, initializes variables and triggers.
/// </summary>
protected virtual void Awake();
/// <summary>
/// Resets the puzzle to the initial state and calls 'UnTrigger' on Triggers, so the player can interact with it again.
/// </summary>
public virtual void Reset();
/// <summary>
/// Accepts the solution for the puzzle.
/// </summary>
protected virtual void AcceptSolution();
/// <summary>
/// The method that will be passed through the delegates to all of the triggers.
/// It will be invoked whenever the triggers are triggered.
/// The id of the respective trigger will be passed.
/// </summary>
protected virtual void TriggerPuzzle(int id);
It is highly recommeded to see what the default logic is present in all given methods.
Note that Reset defines the actions that must be taken to reset the puzzle; such as reset the count of completed steps, reset isSolved field, and more importantly UnTriggers all activated triggers.
As up to TriggerPuzzle, it provides the logic of puzzle, and when it thinks that the puzzle is solved, calls out AcceptSolution. It also may call out the failure method of the Puzzle Handler.
It is not recommended to change AcceptSolution or Awake; or at least, make sure to include the base implementation of both. Overriding these methods without including base implementation may lead to unexpected issues, unless you really know what you are doing.
Example on how to safely override Awake:
protected override void Awake()
// your custom implementation