Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Multidimensional Array -- saving as a field on a Component?

Discussion in 'Project Tiny' started by Berzee, Dec 17, 2018.

  1. Berzee


    Sep 3, 2013
    This came up while I was looking into A* pathfinding for tilemaps. I wanted to loop through a Tilemap2D's tiles, create a 2D array out of them, and then save the resulting array into a component so that I would not need to rebuild it every time I need to run pathfinding. But I don't see an appropriate field type for saving a multidimensional array, and possibly that's by design?

    If that's not possible (or even if it is) I could also just rebuild the array each time, or write the pathfinding algorithm to work directly with the 1D tiles array, or save the 2D array as a global variable in the pathfinding system. Anyone have thoughts on which approach is most in the ECS spirit? =)
  2. vincismurf


    Feb 28, 2013
    I think you can use a static class to hold the array

    Code (JavaScript):
    1. namespace game {
    2. export class GameManager {
    3. public static map: number[] ;
    4. }
    5. }
    access via;

    I belive
  3. timmehhhhhhh


    Sep 10, 2013
    i was surprised to see that arrays work on components at all, as these are not currently allowed in 'non-tiny' ECS components (even fixed arrays were removed in favor of dynamic buffers). i'd second @vincismurf and consider putting this at the system level.

    you will probably find similar recommendations in the main ECS sub-forum, like here.