Vector3Int Clamp

Try to clamp a Vector3Int instance used to set boundaries on a Tilemap

    Vector3Int transcriptionTouche;
    private Vector3Int min;
    private Vector3Int max;

private void Start()
        //Instantiate and Clamp the transcription touch;
        transcriptionTouche = new Vector3Int();

        min = new Vector3Int(0, 0, 0);
        max = new Vector3Int(21, 21, 1);

        transcriptionTouche.Clamp(min, max);


transcriptionTouche is then used as Vector3Int to determine the touched Tile on the Tilemap, but when launching the application under the editor, it is still possible to go outside of the boundaries, and a Debug.log on transcriptionTouche confirms that.

Any idea why the Clamp is not working?

The method Clamp is a mutating method of the Vector3Int struct. You have to call it when you want to clamp it. It’s not a “setting” or something like that. Btw here’s the implementation of the Clamp method.

As you can see it literally just modifies the x, y and z values so they are inside the given min and max bounds.