Skip to content

Find Valid Random Position 2D

Find a valid random Vector2 world position by generating candidate positions and testing them with one or more 2D validators.

This is a good fit for 2D spawning, tilemap placement, and gameplay systems where a random point must also avoid collisions or satisfy map rules.

How It Works

  1. A Random Position generator creates a candidate 2D position.
  2. Each validator checks that candidate.
  3. If they all pass, the action stores the position and sends the success event.
  4. If no valid position is found after the allowed number of attempts, the action sends the failure event.

Parameters

Parameter Description
Random Position Generator block that creates candidate positions to test.
Validators Optional list of validator blocks. All assigned validators must pass for the candidate to be accepted.
Max Attempts Maximum number of tries before the action fails. Values below 1 are treated as 1.
Store Position Stores the valid world position in a Vector2 variable.
Position Found Optional Bool output set to True on success and False before searching begins.
Success Event Optional event sent when a valid position is found.
Failure Event Optional event sent when no valid position is found.

Common Uses

  • Spawn items or enemies inside a 2D level while avoiding blocked areas.
  • Pick positions inside a circle, ring, box, or tilemap.
  • Filter candidate positions with collision, tile, or distance checks.

Generator And Validator Blocks

The exact options come from the action blocks you add in the inspector.

Common 2D generators include:

  • Random Position In Box 2D
  • Random Position In Circle
  • Random Point In Ring 2D
  • Random Position In Tilemap

Common 2D validators include:

  • Min Distance From Game Object 2D
  • Check Circle Clear 2D
  • Check Box Clear 2D
  • Tilemap Contains Position
  • Tilemap Has Tile
  • Tilemap No Tile
  • Check Tilemap Wall Clear

Notes

  • At least one valid Random Position generator is required.
  • Validators are optional. If none are assigned, the first generated candidate is accepted.
  • Invalid numeric results are rejected before validator checks run.

See also