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.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

C# Multidimensional Arrays & iOS

Discussion in 'Scripting' started by JooZ, Apr 20, 2015.

  1. JooZ

    JooZ

    Joined:
    May 18, 2013
    Posts:
    5
    Hi,
    I have the following (simple) piece of code:

    Code (CSharp):
    1.         int[] dim = new int[4];
    2.         dim[0] = 3;
    3.         dim[1] = 4;
    4.         dim[2] = 2;
    5.         dim[3] = 7;
    6.  
    7.         double [,,,] myValues;
    8.         myValues = new double[dim[0], dim[1], dim[2], dim[3]];
    It works perfectly in the editor or in a desktop build, but fails when compiled for iOS with the following error:
    Is it linked with iOS only? Why are the multidimensional arrays not supported?

    What is the alternative?

    Thanks!
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    So googling around, it appears arrays that are more than 3 dimensions in size (yours is 4D) don't work on iPhones.

    I know that AOT compiles up every class so that they exist in the build and aren't generated JIT. They probably auto-generate arrays up to 3 dimensions only when doing so.

    Don't use a 4D array... honestly, I can't think of many reasons to ever use a 4D array. Define a new class/struct instead.
     
  3. JooZ

    JooZ

    Joined:
    May 18, 2013
    Posts:
    5
    I was using 4D because it is convenient to manipulate (multidimensional interpolation of data). I guess I will probably go with 2D matrices instead, with some methods to extract the right value easily.

    Thanks a lot for your answer!