0
\$\begingroup\$

In the built in Tile Palette tilemap editor, you can choose a GameObject brush to set custom tile GameObjects. How would I be able to set a gameObject onto a tile through a script?. There is no function for this in the tilemap class, or at least the documentation does not mention anything, so how would this work?

Details:

I have a few prefabs that I would like to use the "gameObject brush" on; I also have a tilemap ready to place the tiles.

\$\endgroup\$
0

2 Answers 2

1
\$\begingroup\$

When you are adding the instance of Tile to the tilemap via SetTile, the gameObject property of the tile instance will be cloned like a prefab and made a child of the tilemap.

I am using some code like this in my project:

aTileMap.SetTile(tilePosition, new Tile() { 
    sprite = theSprite,
    gameObject = tilePrefab
});
\$\endgroup\$
-1
\$\begingroup\$

You can utilize the Prefab Brush tool for your purpose. There are various tutorials available on YouTube that can guide you through its usage.

By default, selecting the prefab brush from the menu can be challenging. Therefore, I developed a tool to simplify the visualization process. Since I couldn't use the TileMap Palette, I created a custom palette to achieve the desired results.

You can find the Prefab Painter tool on GitHub at the following link: https://github.com/smkplus/prefab-painter. It provides a more intuitive approach to working with prefabs in your Unity projects.

In the provided link, you'll also find an image demonstrating the tool's interface: image

Additionally, there is a GIF showcasing the tool in action: 135707548-43bd5a32-6754-4434-bea6-8c02a6e8507e

Feel free to explore the Prefab Painter tool and experiment with its features to enhance your prefab workflow.

\$\endgroup\$
1
  • \$\begingroup\$ This is not useful, I am fully aware of that brush tool and it's uses, but I am looking for a way to place prefabs like this through a C# SCRIPT. \$\endgroup\$ Commented Jun 26, 2023 at 20:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .