2025 📆 Unity Prototyping
For Saudade we were working with Unity 6000.0.21f1.
The goal for us was to make level design easier and keep all blocks aligned onto a grid. We determined that we needed three main tools : an eraser, a pencil (to place a single block) and a rectangle tool (to place big chunks of blocks at once).
Since we wanted anyone to be able to add new types of blocks quickly, I created a ScriptableObject named “Tool3DGrid_Tilemap” which contains a list of GameObject (each GameObject will be considered as a tile).
To make the tool as reusable on other projects as possible, we chose not to use any custom script from Saudade in the code of the tool, hence why we chose to use GameObjects.
I wanted the tool to have it’s own window so I had to look into the EditorWindow (Scripting API: EditorWindow) system. It also works with the new Unity UI Toolkit but it wasn’t necessary in our case, so we didn’t get to experiment with it. To open the tool you need to go into Window/UI Toolkit/Tool3DGrid_EditorWindow.
Tool3DGrid_Tilemap appearance in Unity
To present all the available “blocks” in a grid, I made the GenerateTilemapMenu() function : https://github.com/alvina-dr/tool-3d-grid/blob/main/Tool3DGrid_EditorWindow.cs#L465
Unity takes a little bit of time to load the preview of the prefabs, so I added a while loop to wait until we get the preview or we’ve tested a certain (subjectively chosen) number - to avoid completely blocking the engine if there’s a problem with a preview for example.
Whether we are in paint or rectangle mode, there’s always a preview of the current selected block when the mouse hovers over the scene panel. This preview is instantiated in the PreviewPrefabInWorld() function. In the future, it would be nice to differentiate the appearance of previews from the actual built GameObject. It might help level designers to understand better where the preview is (would be more user friendly in general).

To see the PreviewPrefabInWorld() function on github : https://github.com/alvina-dr/tool-3d-grid/blob/main/Tool3DGrid_EditorWindow.cs#L421
An important thing to note is that we used (GameObject)PrefabUtility.InstantiatePrefab(CurrentObject) to instantiate GameObjects in the scene while the game is not in play AND keep them as a prefab. Unlike the Instantiate(CurrentObject) line which would have instantiated them as a cloned instantiated version of the prefab (it would have caused problems down the line everytime we wanted to modify a block’s prefab for example).
Another point to take into account, was collision with the preview. We are using Physics.Raycast to determine where the cursor points in the scene, but the preview when instantiated also has a collider which means that we get a weird bug where the preview gets closer and closer to the camera. To avoid that, we decided to change the layer of the preview to “Ignore Raycast” using SetGameLayerRecursive() : https://github.com/alvina-dr/tool-3d-grid/blob/main/Tool3DGrid_EditorWindow.cs#L512
From showing the preview to actually building the block into the environment there was only one step. All you have to do is instantiate the chosen prefab at the preview’s position and rotation. We chose to instantiate a brand new prefab to avoid messing with the layers that we changed for the preview by trying to change them back to what they were (some were default, others were specific to Audio, etc…). This takes place in the Build() function : https://github.com/alvina-dr/tool-3d-grid/blob/main/Tool3DGrid_EditorWindow.cs#L258
The line Undo.RegisterCreatedObjectUndo(instance, "Created go") allows us to use Ctrl + Z after building the block to remove it.
And that’s basically it for the pencil tool. But designing the rectangle tool was a little bit more complex.
The rectangle tool can be divided into three functions : the PreviewRectangle() function, the BuildRectangle() function and the StartRectangle() function. What happens is that when the user clicks somewhere, we register a collision point, just like the pencil. That’s the start of our rectangle (when we call StartRectangle()).
Then the user can drag their mouse around the scene (without releasing the mouse button) and they will be able to see a preview rectangle that goes from the start of their rectangle to the current point that their mouse points to. Until the mouse button is released, the appearance of this rectangle is managed in PreviewRectangle(). The difference for this second part is that we don’t use the classical Physics.Raycast but the Plane.Raycast (Scripting API: Plane.Raycast). Our rectangle will always be on the XZ plane that we define in StartRectangle().
When the user releases the mouse button, the rectangle is built through the BuildRectangleFunction(). Just like in the PreviewPrefabInWorld() function, we instantiate brand new prefabs and delete the preview ones.
StartRectangle() : https://github.com/alvina-dr/tool-3d-grid/blob/main/Tool3DGrid_EditorWindow.cs#L270
PreviewRectangle() : https://github.com/alvina-dr/tool-3d-grid/blob/main/Tool3DGrid_EditorWindow.cs#L295
BuildRectangle() : https://github.com/alvina-dr/tool-3d-grid/blob/main/Tool3DGrid_EditorWindow.cs#L387
We also had to improve the performance of the rectangle tool because it was making our level designer’s computer crash. Sometimes the difference of size of the rectangle between two frames was so big that Unity needed to instantiate many previews and the computer just couldn’t do it. To solve that, I made an int variable called “maxPrefabInstantiation” that we can change depending on the computer. It puts a limit on the number of prefab that the program will instantiate at the given frame (so if the rectangle is really big, it might take a few seconds for the whole rectangle to appear).
For now this does the work, but during my tests I saw numbers that weren’t logical with the rectangles we wanted to draw. It seemed like the collision point with the XZ plane wasn’t what it should have been and was instead indicated as really far away - which would explain why we sometimes had crashes on small rectangles yet the fix keeps the computer from crashing.
Finally the erase tool. It’s a very simple tool that calls the Erase() function on click. With a Physics.Raycast, we detect a collision and delete the object responsible for that collision.
https://github.com/alvina-dr/tool-3d-grid/blob/main/Tool3DGrid_EditorWindow.cs#L409
The problem with that is that sometimes the collider is a child of the prefab of the block. So we might be deleting the child of a dirt block and leaving an empty parent somewhere in the scene. Or if the block has several colliders, we are only destroying a part of it. In any case there’s a real flaw with the erase tool (if we want to be organised). It’s a possible improvement that I will be looking into in the future.
The line Undo.DestroyObjectImmediate(hit.transform.gameObject) allows us to reverse the deletion of an object.
We also added a few shortcuts (for example [T] allows the user to rotate the preview on the Y axis and [R] + mouse click erases the targeted object).
There are lots of improvements that could be made to this tool, but ultimately, the goal was to make a game, so we had to make choices between what was making the whole team gain time and what was making us - programmers - lose too much. I think we got the balance pretty right and it’s a good enough base for the future !