Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  3. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Array of arrays in component

Discussion in 'Project Tiny' started by Rupture13, Feb 15, 2019.

  1. Rupture13

    Rupture13

    Joined:
    Apr 12, 2016
    Posts:
    131
    Hi,
    For a ClickerComponent, which has the function of keeping track of clicks and swipes, I would like to store my swipes as sequences of clicking-points = Array of arrays of Vector2.

    However, adding fields to a component only supports 1 level of array-ing.
    It also doesn't support adding a field of a custom type (else I could just have an array of a custom class that itself has an array).
    I could use an array of entityReferences, and then have the entities store arrays, but I don't think that's either best practice or very performant.

    Is there a way of doing this?
    If not, is there an alternative for doing what I want?
     
  2. Rupture13

    Rupture13

    Joined:
    Apr 12, 2016
    Posts:
    131
    Ok, I posted too soon. I figured it out now.

    Apparently, creating your own custom field types is possible by creating Tiny Structs:


    You can then fill your struct with fields like you would fill your component, but you can use this new struct as a field type in components :) (or in other structs).
     
  3. Rupture13

    Rupture13

    Joined:
    Apr 12, 2016
    Posts:
    131
    Ok maybe not :/

    When trying to run the project, it fails at step "Generating Bindings" with following error:
    System.Exception: Cannot export type UTiny.DynamicArray`1<game.PointArray> because it has nested dynamic array types!


    It seems like it's not possible to use nested dynamic arrays. And since you can only select dynamic arrays and not static arrays, it seems you can't nest arrays at all in a component or struct.
     
  4. abeisgreat

    abeisgreat

    Joined:
    Nov 21, 2016
    Posts:
    44
    Hmm, I don't have any insight here, but you could always just serialize the points into JSON and store it in a string on the Component. It wouldn't be super fast, but I bet it would be fast enough.
     
  5. boringName

    boringName

    Joined:
    Jul 20, 2016
    Posts:
    8
    I've just ran into this error too while trying to code a dialog tree. Googling lead me to this thread.

    My error stated:


    Build step 'Generating Bindings' failed with exception: System.Exception: Tiny: Unhandled Exception:
    System.Exception: Cannot export type UTiny.DynamicArray`1<game.TextNode> because it has nested dynamic array types!


    I think this might be a feature. The developers have mentioned "code that isn't performant should be rejected as a compiler error", and preventing implementations of nested dynamic array makes sense from that perspective; nested dynamic arrays are generally cache unfriendly.
     
    Last edited: May 6, 2019