Version: Unity 6.5 Alpha (6000.5)
LanguageEnglish
  • C#

Tilemap.SetTilesBlock

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public void SetTilesBlock(BoundsInt position, TileBase[] tileArray);

Parameters

Parameter Description
position The area to fill.
tileArray The array of Tiles to be placed.

Description

Fills an area with array of Tiles.

This method is a faster way to set multiple tiles in an area than calling SetTile for each tile. The bounds size must match the array size. For example bounds of 1x2x3 needs an array length of 6.

// Fill area on Tilemap with checkerboard pattern of tileA and tileB
using UnityEngine;
using UnityEngine.Tilemaps;

public class ExampleClass : MonoBehaviour { public TileBase tileA; public TileBase tileB; public BoundsInt area;

void Start() { TileBase[] tileArray = new TileBase[area.size.x * area.size.y * area.size.z]; for (int index = 0; index < tileArray.Length; index++) { tileArray[index] = index % 2 == 0 ? tileA : tileB; } Tilemap tilemap = GetComponent<Tilemap>(); tilemap.SetTilesBlock(area, tileArray); } }

Refer to Scriptable Tiles and Tilemap for more information.


Declaration

public void SetTilesBlock(BoundsInt position, TileArray tileArray);

Parameters

Parameter Description
position The area to fill.
tileArray The array of Tiles to place.

Description

Fills an area with an array of Tiles.

This method is a faster way to set multiple tiles in an area than calling SetTile for each tile. The bounds size must match the array size. For example bounds of 1x2x3 needs an array length of 6.

// Fill area on Tilemap with checkerboard pattern of tileA and tileB
using UnityEngine;
using UnityEngine.Tilemaps;
using Unity.Collections;

public class ExampleClass_Native : MonoBehaviour { public TileBase tileA; public TileBase tileB; public BoundsInt area;

void Start() { Tilemap.TileArray tileArray = new Tilemap.TileArray(area.size.x * area.size.y * area.size.z, Allocator.Temp); for (int index = 0; index < tileArray.Length; index++) { tileArray[index] = index % 2 == 0 ? tileA : tileB; } Tilemap tilemap = GetComponent<Tilemap>(); tilemap.SetTilesBlock(area, tileArray); } }