Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

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.