Placing units on a scalable grid in editor?

I want to make a turn-based strategy game based on a cube grid. The units should be placed on the grid in the editor before the game runs, so they can move in game similar to chess.

My “solution” was placing child actors in the grid manually, so I can set their attached unit in the editor but that is barely scalable.

The grid class adds child actor cubes based on grid size (x/y) and then i want to attach/assign a unit to the child actor component cube instance. If the cubes are generated only in construction, I can’t access them in the editor. How would you do this?

How grid looks optically. In picture, it’s 8*8:

How grid is constructed:

Cube class has Child Actor Component placeholder for unit that can be changed to any unit actor assigned to the block:

Hello,

welcome to the forum :slight_smile:

You could perhaps use a variable inside your construction script, like this:

If you mark it as Instance Editable then it will be editable per instance for each tile, and it will appear in the editor when selecting a tile in your level.


image

2 Likes

(post deleted by author)

Tried it now but I don’t think it’s what I need. When a block is on its own, so not in a grid, I can edit Unit in editor. When I create a block with the grid constructor, it shows in the viewport as child actors but not in the details panel. I can’t edit them.

Those squares are on grid, and you know size of each.

You can calculate their real world X-Y coordinates , then divide by size, and you get number for each tile.

1 Like

I can also access and set the unit in the event graph/constructor with index but I was curious if there is an easier, faster way. For example making the blocks accessible in the editor.

Assuming central piece is in [0,0,0], and size of single cell is [wx,wy].

You can get current actor location. Substract central piece location. Then divide by wx.wy (trunc remainder). And you get cell coordinates.

You can (and should) make all pieces as separate actors, and each piece can calculate its own cell coordinates. Then piece sets its own coordinate, all can be done in constructor.

Imo. This is easiest way from coding pov. You just place pieces, snap to grid, they handle themselves.

Ps.
One of next steps will be creating map for those tiles. Keywords to feed google with are: “Wave function collapse”. And here is one of many vids from YT:

1 Like