Placeable

Create Placeables

Create a new placeable in the same way that you created the placeable database.

Just choose “Placeable” now instead of “Placeable Object Database”

You will see following preview in the inspector:

Use the prefab of a 3D Model of your choice and assign it to the Prefab holder.

There are some requirements for 3D models that you need to consider for a flawless experience:

  • The 3D model should have a collider assigned so we can interact with it after placing it on the grid.

  • Also the pivot of the model should be centered in x and z axis to ensure smooth rotation on the grid

If the model already meets these requirements, you can just continue with the documentation, otherwise either first read the section “Prepare your 3D models” or simply continue with the documentation and fix the model later on

After adding your 3D model, click on Calculate Object Size, which will pre fill your Size property

Go to your previously created database and add this placeable to the database:

Now start the demo scene and try to place your object. The shop UI buttons should be prefilled automatically based on the placeables that are in your database:

Placeable properties

As you probably already noticed there are some other properties for the placeables that you can configure. You already know that you need to assign a prefab and then click on the calculate button to prefill the size property. Now let's go over the other properties.

Icon

The icon is used for instantiating the shop buttons with the item icons.

Simply create a sprite of an image of your object and assign it to this property.

If the property is empty, the shop ui buttons will fallback to the placeable name and display the name instead.

Grid Type

The grid type is used as an info to specify in which grid data the object position is stored after placement.

Detailed explanation

The placement system of the grid internally handles multiple GridData classes. A GridData represents an encapsulated state that holds the grid positions and the PlacementInfo for each position, but only from objects of the same gridType. This means that all objects of type “Blocking” will be stored in the same GridData and also the available positions will be calculated based on this grid data. The data does not know anything about other object types. This allows us to store one object of type blocking and one object of type terrain on the same grid position (since it's handled by different grid data classes).This is pretty handy, since we may want to have the option to place a building on top of a terrain.

You can not place 2 objects of the same type on the same grid position, but you can have as many grid types as you want (just extend the GridType enum script)

Object group info

The object group info is basically only for grouping the objects into different tabs for the shop UI. The shop currently has 4 different tabs (Building, Nature, Decoration & terrain)

For each tab only the objects that belong to the same group will be shown in the shop

Dynamic size

This is an additional grid system feature that allows you to scale your object dynamically on runtime, based on your grid cell size. The object transform scale will always have the cell size as value, so that a dynamic object of scale 1x1 will always occupy exactly 1 cell, independent of the cell size. I added this feature because of the terrain objects when using a bigger cell size. You basically always want to fill out the full occupied cells with the terrain, therefore we need to scale it. But this also works for all other objects, not only terrains.

If a dynamic object would occupy for example 2x3 cells with a cell size of 1, it will be scaled to also occupy 2x3 cells with any other arbitrary cell size.

Here you can see an example of terrain objects, one with and one without dynamic size.

(left is dynamic and right is fixed size)

Last updated