How to get grid panel's child position (x, y)?

Hi, is there any way to get the position (x, y) of a certain child in a grid panel?

Thanks.

  • you know the desired size of the entire grid panel
  • you know how many rows and columns there are
  • you know the size of each grid cell (gridpanel_size.x / columns & gridpanel_size.y / rows) (or query child for its Desired Size)
  • you know which (row, column) a grid piece occupies
  • you know the padding of the container and padding of the child (if any)
  • if you need just the relative location inside the panel, the above is enough
  • if you need absolute screen location, or relative location to something else in the screen space:

With all the above, you can math it out. If you’re not sure how, do it on a sheet of paper and translate into BP nodes. Which will feel a bit backwards at first…


It gets a tad trickier when you have a non-uniform grid.

1 Like

You can use something like this but it depends on what you’re trying to do, for example are you trying to take the viewport size into consideration or just the space within the panel.

1 Like

Before you jump on the Cached Geometry bandwagon, do read its tooltip. If you’re OK with it, that could work, too. :crossed_fingers:

2 Likes

Thanks. I’m just trying to take the grid space into consideration.

Thanks a lot. But how can I get the child in a certain cell, considering I know the row/column? “Get child at” node only has an index.

You surely know the number of rows / columns. Modulo helps, but it can be done the hard way, too.

1 Like

How would you find out the index, if you know the row and column of the cell, through modulo though? I can’t figure it out.

I see a lot of confusion on this page. And multiple questions that differ from what it initially was.

How to get XY pixel position has been answered above.

How to get XY in “grid space” (row + column) is possible when every item on the grid has a uniform size, so that you can say “A row of 100px is made of 5 items of 20px”, then it’s easy enough to get a X or Y index in grid space, if your pixel position of the item is at 80 pixels then it is at index 4 (count indexes 0 1 2 3 4, indexes always start at 0).

If you have only the index of the item, you can calculate the row and column position the easiest using modulo.

If you have rows sized 5 columns, 76 items on it would give you?
You get 15 full rows and a column extra.

afbeelding

row index 15, column index 0.

Modulo gives you a remainder of a division, which is your “extra column(s)”.

afbeelding

Modulo - Wikipedia

Because modulo is not used for that. If you know the row and column you do:
(RowSize * RowIndex) + ColumnIndex

Basically you fill imaginary rows by their maximum size and add the remaining columns.

1 Like