Populate Scriptable Objects Automatically











up vote
1
down vote

favorite












A few of my Scriptable Objects(used for seeding my initial game data) contain large 2 dimensional arrays (like 10x10), the data of which i am generating with an external Python script. I do use the Odin inspector plugin as well, to serialize the 2d array for me and provide me with a nice representation of that array inside the Unity editor.



I am simply doing it like this :



[TableMatrix()]
public int[,] table = new int[10, 10];


and this is just an Odin SerializedScriptableObject class.



The problem is, I really want to avoid having to add the 10x10 elements by hand using the Unity editor and also I want my objects to have variable 2d array sizes, one could beb (10,10), another could be (5,5). Is there a way to populate my scriptable objects programmatically to achieve that ? (Or does the Odin inspector plugin support something like that if anyone knows ?)



Thanks !










share|improve this question
























  • You're using jagged array, what happens if you make the matrix like [ ][ ] instead of the jagged array? If you are okay to avoid jagged arrays I can offer a solution :D
    – Lotan
    Nov 19 at 16:01










  • Hi @Lotan, please do, the way the array is initialized doesn't matter. I can definitely work around that. What I am mostly concerned with is being able to have a variable size array on each of my scriptable objects and be able to populate them programmatically.
    – Spyros
    Nov 19 at 19:18






  • 1




    @Lotan It's the other way around, a jagged array is an arrays of arrays. The OP is using a multidimensional array (specifically a 2D array)
    – Ghost4Man
    Nov 20 at 19:01










  • @Ghost4Man that's the way I think will work, but I don't have unity these days to test it :(
    – Lotan
    Nov 21 at 7:49










  • How is the data getting from python into unity? Or is that what you are asking?
    – Leo Bartkus
    Nov 24 at 8:22















up vote
1
down vote

favorite












A few of my Scriptable Objects(used for seeding my initial game data) contain large 2 dimensional arrays (like 10x10), the data of which i am generating with an external Python script. I do use the Odin inspector plugin as well, to serialize the 2d array for me and provide me with a nice representation of that array inside the Unity editor.



I am simply doing it like this :



[TableMatrix()]
public int[,] table = new int[10, 10];


and this is just an Odin SerializedScriptableObject class.



The problem is, I really want to avoid having to add the 10x10 elements by hand using the Unity editor and also I want my objects to have variable 2d array sizes, one could beb (10,10), another could be (5,5). Is there a way to populate my scriptable objects programmatically to achieve that ? (Or does the Odin inspector plugin support something like that if anyone knows ?)



Thanks !










share|improve this question
























  • You're using jagged array, what happens if you make the matrix like [ ][ ] instead of the jagged array? If you are okay to avoid jagged arrays I can offer a solution :D
    – Lotan
    Nov 19 at 16:01










  • Hi @Lotan, please do, the way the array is initialized doesn't matter. I can definitely work around that. What I am mostly concerned with is being able to have a variable size array on each of my scriptable objects and be able to populate them programmatically.
    – Spyros
    Nov 19 at 19:18






  • 1




    @Lotan It's the other way around, a jagged array is an arrays of arrays. The OP is using a multidimensional array (specifically a 2D array)
    – Ghost4Man
    Nov 20 at 19:01










  • @Ghost4Man that's the way I think will work, but I don't have unity these days to test it :(
    – Lotan
    Nov 21 at 7:49










  • How is the data getting from python into unity? Or is that what you are asking?
    – Leo Bartkus
    Nov 24 at 8:22













up vote
1
down vote

favorite









up vote
1
down vote

favorite











A few of my Scriptable Objects(used for seeding my initial game data) contain large 2 dimensional arrays (like 10x10), the data of which i am generating with an external Python script. I do use the Odin inspector plugin as well, to serialize the 2d array for me and provide me with a nice representation of that array inside the Unity editor.



I am simply doing it like this :



[TableMatrix()]
public int[,] table = new int[10, 10];


and this is just an Odin SerializedScriptableObject class.



The problem is, I really want to avoid having to add the 10x10 elements by hand using the Unity editor and also I want my objects to have variable 2d array sizes, one could beb (10,10), another could be (5,5). Is there a way to populate my scriptable objects programmatically to achieve that ? (Or does the Odin inspector plugin support something like that if anyone knows ?)



Thanks !










share|improve this question















A few of my Scriptable Objects(used for seeding my initial game data) contain large 2 dimensional arrays (like 10x10), the data of which i am generating with an external Python script. I do use the Odin inspector plugin as well, to serialize the 2d array for me and provide me with a nice representation of that array inside the Unity editor.



I am simply doing it like this :



[TableMatrix()]
public int[,] table = new int[10, 10];


and this is just an Odin SerializedScriptableObject class.



The problem is, I really want to avoid having to add the 10x10 elements by hand using the Unity editor and also I want my objects to have variable 2d array sizes, one could beb (10,10), another could be (5,5). Is there a way to populate my scriptable objects programmatically to achieve that ? (Or does the Odin inspector plugin support something like that if anyone knows ?)



Thanks !







c# unity3d






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 13:46









Julxzs

363213




363213










asked Nov 10 at 9:38









Spyros

23.3k1971110




23.3k1971110












  • You're using jagged array, what happens if you make the matrix like [ ][ ] instead of the jagged array? If you are okay to avoid jagged arrays I can offer a solution :D
    – Lotan
    Nov 19 at 16:01










  • Hi @Lotan, please do, the way the array is initialized doesn't matter. I can definitely work around that. What I am mostly concerned with is being able to have a variable size array on each of my scriptable objects and be able to populate them programmatically.
    – Spyros
    Nov 19 at 19:18






  • 1




    @Lotan It's the other way around, a jagged array is an arrays of arrays. The OP is using a multidimensional array (specifically a 2D array)
    – Ghost4Man
    Nov 20 at 19:01










  • @Ghost4Man that's the way I think will work, but I don't have unity these days to test it :(
    – Lotan
    Nov 21 at 7:49










  • How is the data getting from python into unity? Or is that what you are asking?
    – Leo Bartkus
    Nov 24 at 8:22


















  • You're using jagged array, what happens if you make the matrix like [ ][ ] instead of the jagged array? If you are okay to avoid jagged arrays I can offer a solution :D
    – Lotan
    Nov 19 at 16:01










  • Hi @Lotan, please do, the way the array is initialized doesn't matter. I can definitely work around that. What I am mostly concerned with is being able to have a variable size array on each of my scriptable objects and be able to populate them programmatically.
    – Spyros
    Nov 19 at 19:18






  • 1




    @Lotan It's the other way around, a jagged array is an arrays of arrays. The OP is using a multidimensional array (specifically a 2D array)
    – Ghost4Man
    Nov 20 at 19:01










  • @Ghost4Man that's the way I think will work, but I don't have unity these days to test it :(
    – Lotan
    Nov 21 at 7:49










  • How is the data getting from python into unity? Or is that what you are asking?
    – Leo Bartkus
    Nov 24 at 8:22
















You're using jagged array, what happens if you make the matrix like [ ][ ] instead of the jagged array? If you are okay to avoid jagged arrays I can offer a solution :D
– Lotan
Nov 19 at 16:01




You're using jagged array, what happens if you make the matrix like [ ][ ] instead of the jagged array? If you are okay to avoid jagged arrays I can offer a solution :D
– Lotan
Nov 19 at 16:01












Hi @Lotan, please do, the way the array is initialized doesn't matter. I can definitely work around that. What I am mostly concerned with is being able to have a variable size array on each of my scriptable objects and be able to populate them programmatically.
– Spyros
Nov 19 at 19:18




Hi @Lotan, please do, the way the array is initialized doesn't matter. I can definitely work around that. What I am mostly concerned with is being able to have a variable size array on each of my scriptable objects and be able to populate them programmatically.
– Spyros
Nov 19 at 19:18




1




1




@Lotan It's the other way around, a jagged array is an arrays of arrays. The OP is using a multidimensional array (specifically a 2D array)
– Ghost4Man
Nov 20 at 19:01




@Lotan It's the other way around, a jagged array is an arrays of arrays. The OP is using a multidimensional array (specifically a 2D array)
– Ghost4Man
Nov 20 at 19:01












@Ghost4Man that's the way I think will work, but I don't have unity these days to test it :(
– Lotan
Nov 21 at 7:49




@Ghost4Man that's the way I think will work, but I don't have unity these days to test it :(
– Lotan
Nov 21 at 7:49












How is the data getting from python into unity? Or is that what you are asking?
– Leo Bartkus
Nov 24 at 8:22




How is the data getting from python into unity? Or is that what you are asking?
– Leo Bartkus
Nov 24 at 8:22












3 Answers
3






active

oldest

votes

















up vote
1
down vote



accepted
+50










Sorry for the late response @Spyros.



My approach will be similar to @D Manokhin approach, but instead of using jagged array I'll use a multidimensional array (cause you can build a custom editor script to visualize them, I'm pretty sure you can visualize jagged arrays on editor without plugins, I've never used Odin plugin).



So I delcare one class who will store the structs called TileData:



using UnityEngine;
using System.Collections;

[System.Serializable]
public class TileData
{
/*
* rows
[rowData][rowData][rowData]
[cell] ->value
->type
[cell] ->value
->type
[cell] ->value
->type
*/

[System.Serializable]
public struct cell
{
public float value;
public string type;
}


[System.Serializable]
public struct rowData
{
public cell row;
}

public rowData rows;

}


I used value and type as an "examples", it's absolutly up to you, you can also store Vector3 if you want!



Then, how to call and use this kind of structure? Let's see:



using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Matrix : MonoBehaviour {

//declare the structure that will store the data
public TileData tileData = new TileData();

//those are public so you could make the matrix with the size you want..
//..ideally dynamically call it from your python file requisits
public int horizontalMatrixSize = 10;
public int verticalMatrixSize = 10;

// Use this for initialization
void Start()
{
//Create the matrix structure and fill it
tileData.rows = new TileData.rowData[horizontalMatrixSize];
for (int i = 0; i < tileData.rows.Length; i++)
{
tileData.rows[i].row = new TileData.cell[verticalMatrixSize];
for (int u = 0; u < tileData.rows[i].row.Length; u++)
{
tileData.rows[i].row[u].value = GetValuesFromPythonFileOrWhatever();
tileData.rows[i].row[u].type = GetValuesFromPythonFileOrWhatever();
}
}
}

}


But if you really like the jagged structure, you can still use it (but remember that will not be represented on editor) like this:



using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Matrix : MonoBehaviour {
//declare the structure that will store the data
[SerializeField] private float[,] grayscaleBidimensional = null;

//those are public so you could make the matrix with the size you want..
//..ideally dynamically call it from your python file requisits
public int horizontalMatrixSize = 10;
public int verticalMatrixSize = 10;

// Use this for initialization
void Start()
{
//Create the matrix structure and fill it
tileData.rows = new TileData.rowData[horizontalMatrixSize];

grayscaleBidimensional = new float[horizontalMatrixSize, verticalMatrixSize];
for (int x = 0; x < horizontalMatrixSize; x++)
{
for (int y = 0; y < verticalMatrixSize; y++)
{
grayscaleBidimensional[x, y] = GetValuesFromPythonFileOrWhatever();
}
}
}

}


Remember that you can make the values of the objects as you want, so they don't need to have an static size!






share|improve this answer






























    up vote
    0
    down vote













    To change an individual value, you can do table[x,y] = (your value). Lets say you want to fill every value with the number one, you could do:



    for (int y = 0; y < 10; y++)
    {
    for (int x = 0; x < 10; x++)
    {
    table[x, y] = 1;
    }
    }


    Hope that answers your question and sorry if the code is wrong - I don't have access to Unity at the moment, so you may need to fiddle around with it.






    share|improve this answer























    • The problem is that scriptable objects would require me to preset the array to be 10x10 elements, while my game data to be seeded contain 5x5, 10x10 or other size arrays. It's basically variable.
      – Spyros
      Nov 19 at 13:26


















    up vote
    0
    down vote













    You should serialize the arrays out to files in python, and then use a Scripted Importer to import them into Unity, construct the arrays in the ScriptableObject, and fill in their values.



    https://docs.unity3d.com/Manual/ScriptedImporters.html






    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237680%2fpopulate-scriptable-objects-automatically%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      1
      down vote



      accepted
      +50










      Sorry for the late response @Spyros.



      My approach will be similar to @D Manokhin approach, but instead of using jagged array I'll use a multidimensional array (cause you can build a custom editor script to visualize them, I'm pretty sure you can visualize jagged arrays on editor without plugins, I've never used Odin plugin).



      So I delcare one class who will store the structs called TileData:



      using UnityEngine;
      using System.Collections;

      [System.Serializable]
      public class TileData
      {
      /*
      * rows
      [rowData][rowData][rowData]
      [cell] ->value
      ->type
      [cell] ->value
      ->type
      [cell] ->value
      ->type
      */

      [System.Serializable]
      public struct cell
      {
      public float value;
      public string type;
      }


      [System.Serializable]
      public struct rowData
      {
      public cell row;
      }

      public rowData rows;

      }


      I used value and type as an "examples", it's absolutly up to you, you can also store Vector3 if you want!



      Then, how to call and use this kind of structure? Let's see:



      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;

      public class Matrix : MonoBehaviour {

      //declare the structure that will store the data
      public TileData tileData = new TileData();

      //those are public so you could make the matrix with the size you want..
      //..ideally dynamically call it from your python file requisits
      public int horizontalMatrixSize = 10;
      public int verticalMatrixSize = 10;

      // Use this for initialization
      void Start()
      {
      //Create the matrix structure and fill it
      tileData.rows = new TileData.rowData[horizontalMatrixSize];
      for (int i = 0; i < tileData.rows.Length; i++)
      {
      tileData.rows[i].row = new TileData.cell[verticalMatrixSize];
      for (int u = 0; u < tileData.rows[i].row.Length; u++)
      {
      tileData.rows[i].row[u].value = GetValuesFromPythonFileOrWhatever();
      tileData.rows[i].row[u].type = GetValuesFromPythonFileOrWhatever();
      }
      }
      }

      }


      But if you really like the jagged structure, you can still use it (but remember that will not be represented on editor) like this:



      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;

      public class Matrix : MonoBehaviour {
      //declare the structure that will store the data
      [SerializeField] private float[,] grayscaleBidimensional = null;

      //those are public so you could make the matrix with the size you want..
      //..ideally dynamically call it from your python file requisits
      public int horizontalMatrixSize = 10;
      public int verticalMatrixSize = 10;

      // Use this for initialization
      void Start()
      {
      //Create the matrix structure and fill it
      tileData.rows = new TileData.rowData[horizontalMatrixSize];

      grayscaleBidimensional = new float[horizontalMatrixSize, verticalMatrixSize];
      for (int x = 0; x < horizontalMatrixSize; x++)
      {
      for (int y = 0; y < verticalMatrixSize; y++)
      {
      grayscaleBidimensional[x, y] = GetValuesFromPythonFileOrWhatever();
      }
      }
      }

      }


      Remember that you can make the values of the objects as you want, so they don't need to have an static size!






      share|improve this answer



























        up vote
        1
        down vote



        accepted
        +50










        Sorry for the late response @Spyros.



        My approach will be similar to @D Manokhin approach, but instead of using jagged array I'll use a multidimensional array (cause you can build a custom editor script to visualize them, I'm pretty sure you can visualize jagged arrays on editor without plugins, I've never used Odin plugin).



        So I delcare one class who will store the structs called TileData:



        using UnityEngine;
        using System.Collections;

        [System.Serializable]
        public class TileData
        {
        /*
        * rows
        [rowData][rowData][rowData]
        [cell] ->value
        ->type
        [cell] ->value
        ->type
        [cell] ->value
        ->type
        */

        [System.Serializable]
        public struct cell
        {
        public float value;
        public string type;
        }


        [System.Serializable]
        public struct rowData
        {
        public cell row;
        }

        public rowData rows;

        }


        I used value and type as an "examples", it's absolutly up to you, you can also store Vector3 if you want!



        Then, how to call and use this kind of structure? Let's see:



        using System.Collections;
        using System.Collections.Generic;
        using UnityEngine;

        public class Matrix : MonoBehaviour {

        //declare the structure that will store the data
        public TileData tileData = new TileData();

        //those are public so you could make the matrix with the size you want..
        //..ideally dynamically call it from your python file requisits
        public int horizontalMatrixSize = 10;
        public int verticalMatrixSize = 10;

        // Use this for initialization
        void Start()
        {
        //Create the matrix structure and fill it
        tileData.rows = new TileData.rowData[horizontalMatrixSize];
        for (int i = 0; i < tileData.rows.Length; i++)
        {
        tileData.rows[i].row = new TileData.cell[verticalMatrixSize];
        for (int u = 0; u < tileData.rows[i].row.Length; u++)
        {
        tileData.rows[i].row[u].value = GetValuesFromPythonFileOrWhatever();
        tileData.rows[i].row[u].type = GetValuesFromPythonFileOrWhatever();
        }
        }
        }

        }


        But if you really like the jagged structure, you can still use it (but remember that will not be represented on editor) like this:



        using System.Collections;
        using System.Collections.Generic;
        using UnityEngine;

        public class Matrix : MonoBehaviour {
        //declare the structure that will store the data
        [SerializeField] private float[,] grayscaleBidimensional = null;

        //those are public so you could make the matrix with the size you want..
        //..ideally dynamically call it from your python file requisits
        public int horizontalMatrixSize = 10;
        public int verticalMatrixSize = 10;

        // Use this for initialization
        void Start()
        {
        //Create the matrix structure and fill it
        tileData.rows = new TileData.rowData[horizontalMatrixSize];

        grayscaleBidimensional = new float[horizontalMatrixSize, verticalMatrixSize];
        for (int x = 0; x < horizontalMatrixSize; x++)
        {
        for (int y = 0; y < verticalMatrixSize; y++)
        {
        grayscaleBidimensional[x, y] = GetValuesFromPythonFileOrWhatever();
        }
        }
        }

        }


        Remember that you can make the values of the objects as you want, so they don't need to have an static size!






        share|improve this answer

























          up vote
          1
          down vote



          accepted
          +50







          up vote
          1
          down vote



          accepted
          +50




          +50




          Sorry for the late response @Spyros.



          My approach will be similar to @D Manokhin approach, but instead of using jagged array I'll use a multidimensional array (cause you can build a custom editor script to visualize them, I'm pretty sure you can visualize jagged arrays on editor without plugins, I've never used Odin plugin).



          So I delcare one class who will store the structs called TileData:



          using UnityEngine;
          using System.Collections;

          [System.Serializable]
          public class TileData
          {
          /*
          * rows
          [rowData][rowData][rowData]
          [cell] ->value
          ->type
          [cell] ->value
          ->type
          [cell] ->value
          ->type
          */

          [System.Serializable]
          public struct cell
          {
          public float value;
          public string type;
          }


          [System.Serializable]
          public struct rowData
          {
          public cell row;
          }

          public rowData rows;

          }


          I used value and type as an "examples", it's absolutly up to you, you can also store Vector3 if you want!



          Then, how to call and use this kind of structure? Let's see:



          using System.Collections;
          using System.Collections.Generic;
          using UnityEngine;

          public class Matrix : MonoBehaviour {

          //declare the structure that will store the data
          public TileData tileData = new TileData();

          //those are public so you could make the matrix with the size you want..
          //..ideally dynamically call it from your python file requisits
          public int horizontalMatrixSize = 10;
          public int verticalMatrixSize = 10;

          // Use this for initialization
          void Start()
          {
          //Create the matrix structure and fill it
          tileData.rows = new TileData.rowData[horizontalMatrixSize];
          for (int i = 0; i < tileData.rows.Length; i++)
          {
          tileData.rows[i].row = new TileData.cell[verticalMatrixSize];
          for (int u = 0; u < tileData.rows[i].row.Length; u++)
          {
          tileData.rows[i].row[u].value = GetValuesFromPythonFileOrWhatever();
          tileData.rows[i].row[u].type = GetValuesFromPythonFileOrWhatever();
          }
          }
          }

          }


          But if you really like the jagged structure, you can still use it (but remember that will not be represented on editor) like this:



          using System.Collections;
          using System.Collections.Generic;
          using UnityEngine;

          public class Matrix : MonoBehaviour {
          //declare the structure that will store the data
          [SerializeField] private float[,] grayscaleBidimensional = null;

          //those are public so you could make the matrix with the size you want..
          //..ideally dynamically call it from your python file requisits
          public int horizontalMatrixSize = 10;
          public int verticalMatrixSize = 10;

          // Use this for initialization
          void Start()
          {
          //Create the matrix structure and fill it
          tileData.rows = new TileData.rowData[horizontalMatrixSize];

          grayscaleBidimensional = new float[horizontalMatrixSize, verticalMatrixSize];
          for (int x = 0; x < horizontalMatrixSize; x++)
          {
          for (int y = 0; y < verticalMatrixSize; y++)
          {
          grayscaleBidimensional[x, y] = GetValuesFromPythonFileOrWhatever();
          }
          }
          }

          }


          Remember that you can make the values of the objects as you want, so they don't need to have an static size!






          share|improve this answer














          Sorry for the late response @Spyros.



          My approach will be similar to @D Manokhin approach, but instead of using jagged array I'll use a multidimensional array (cause you can build a custom editor script to visualize them, I'm pretty sure you can visualize jagged arrays on editor without plugins, I've never used Odin plugin).



          So I delcare one class who will store the structs called TileData:



          using UnityEngine;
          using System.Collections;

          [System.Serializable]
          public class TileData
          {
          /*
          * rows
          [rowData][rowData][rowData]
          [cell] ->value
          ->type
          [cell] ->value
          ->type
          [cell] ->value
          ->type
          */

          [System.Serializable]
          public struct cell
          {
          public float value;
          public string type;
          }


          [System.Serializable]
          public struct rowData
          {
          public cell row;
          }

          public rowData rows;

          }


          I used value and type as an "examples", it's absolutly up to you, you can also store Vector3 if you want!



          Then, how to call and use this kind of structure? Let's see:



          using System.Collections;
          using System.Collections.Generic;
          using UnityEngine;

          public class Matrix : MonoBehaviour {

          //declare the structure that will store the data
          public TileData tileData = new TileData();

          //those are public so you could make the matrix with the size you want..
          //..ideally dynamically call it from your python file requisits
          public int horizontalMatrixSize = 10;
          public int verticalMatrixSize = 10;

          // Use this for initialization
          void Start()
          {
          //Create the matrix structure and fill it
          tileData.rows = new TileData.rowData[horizontalMatrixSize];
          for (int i = 0; i < tileData.rows.Length; i++)
          {
          tileData.rows[i].row = new TileData.cell[verticalMatrixSize];
          for (int u = 0; u < tileData.rows[i].row.Length; u++)
          {
          tileData.rows[i].row[u].value = GetValuesFromPythonFileOrWhatever();
          tileData.rows[i].row[u].type = GetValuesFromPythonFileOrWhatever();
          }
          }
          }

          }


          But if you really like the jagged structure, you can still use it (but remember that will not be represented on editor) like this:



          using System.Collections;
          using System.Collections.Generic;
          using UnityEngine;

          public class Matrix : MonoBehaviour {
          //declare the structure that will store the data
          [SerializeField] private float[,] grayscaleBidimensional = null;

          //those are public so you could make the matrix with the size you want..
          //..ideally dynamically call it from your python file requisits
          public int horizontalMatrixSize = 10;
          public int verticalMatrixSize = 10;

          // Use this for initialization
          void Start()
          {
          //Create the matrix structure and fill it
          tileData.rows = new TileData.rowData[horizontalMatrixSize];

          grayscaleBidimensional = new float[horizontalMatrixSize, verticalMatrixSize];
          for (int x = 0; x < horizontalMatrixSize; x++)
          {
          for (int y = 0; y < verticalMatrixSize; y++)
          {
          grayscaleBidimensional[x, y] = GetValuesFromPythonFileOrWhatever();
          }
          }
          }

          }


          Remember that you can make the values of the objects as you want, so they don't need to have an static size!







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 24 at 23:16

























          answered Nov 24 at 21:09









          Lotan

          1,150215




          1,150215
























              up vote
              0
              down vote













              To change an individual value, you can do table[x,y] = (your value). Lets say you want to fill every value with the number one, you could do:



              for (int y = 0; y < 10; y++)
              {
              for (int x = 0; x < 10; x++)
              {
              table[x, y] = 1;
              }
              }


              Hope that answers your question and sorry if the code is wrong - I don't have access to Unity at the moment, so you may need to fiddle around with it.






              share|improve this answer























              • The problem is that scriptable objects would require me to preset the array to be 10x10 elements, while my game data to be seeded contain 5x5, 10x10 or other size arrays. It's basically variable.
                – Spyros
                Nov 19 at 13:26















              up vote
              0
              down vote













              To change an individual value, you can do table[x,y] = (your value). Lets say you want to fill every value with the number one, you could do:



              for (int y = 0; y < 10; y++)
              {
              for (int x = 0; x < 10; x++)
              {
              table[x, y] = 1;
              }
              }


              Hope that answers your question and sorry if the code is wrong - I don't have access to Unity at the moment, so you may need to fiddle around with it.






              share|improve this answer























              • The problem is that scriptable objects would require me to preset the array to be 10x10 elements, while my game data to be seeded contain 5x5, 10x10 or other size arrays. It's basically variable.
                – Spyros
                Nov 19 at 13:26













              up vote
              0
              down vote










              up vote
              0
              down vote









              To change an individual value, you can do table[x,y] = (your value). Lets say you want to fill every value with the number one, you could do:



              for (int y = 0; y < 10; y++)
              {
              for (int x = 0; x < 10; x++)
              {
              table[x, y] = 1;
              }
              }


              Hope that answers your question and sorry if the code is wrong - I don't have access to Unity at the moment, so you may need to fiddle around with it.






              share|improve this answer














              To change an individual value, you can do table[x,y] = (your value). Lets say you want to fill every value with the number one, you could do:



              for (int y = 0; y < 10; y++)
              {
              for (int x = 0; x < 10; x++)
              {
              table[x, y] = 1;
              }
              }


              Hope that answers your question and sorry if the code is wrong - I don't have access to Unity at the moment, so you may need to fiddle around with it.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Nov 19 at 14:49









              Julxzs

              363213




              363213










              answered Nov 19 at 13:02









              D Manokhin

              598219




              598219












              • The problem is that scriptable objects would require me to preset the array to be 10x10 elements, while my game data to be seeded contain 5x5, 10x10 or other size arrays. It's basically variable.
                – Spyros
                Nov 19 at 13:26


















              • The problem is that scriptable objects would require me to preset the array to be 10x10 elements, while my game data to be seeded contain 5x5, 10x10 or other size arrays. It's basically variable.
                – Spyros
                Nov 19 at 13:26
















              The problem is that scriptable objects would require me to preset the array to be 10x10 elements, while my game data to be seeded contain 5x5, 10x10 or other size arrays. It's basically variable.
              – Spyros
              Nov 19 at 13:26




              The problem is that scriptable objects would require me to preset the array to be 10x10 elements, while my game data to be seeded contain 5x5, 10x10 or other size arrays. It's basically variable.
              – Spyros
              Nov 19 at 13:26










              up vote
              0
              down vote













              You should serialize the arrays out to files in python, and then use a Scripted Importer to import them into Unity, construct the arrays in the ScriptableObject, and fill in their values.



              https://docs.unity3d.com/Manual/ScriptedImporters.html






              share|improve this answer

























                up vote
                0
                down vote













                You should serialize the arrays out to files in python, and then use a Scripted Importer to import them into Unity, construct the arrays in the ScriptableObject, and fill in their values.



                https://docs.unity3d.com/Manual/ScriptedImporters.html






                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  You should serialize the arrays out to files in python, and then use a Scripted Importer to import them into Unity, construct the arrays in the ScriptableObject, and fill in their values.



                  https://docs.unity3d.com/Manual/ScriptedImporters.html






                  share|improve this answer












                  You should serialize the arrays out to files in python, and then use a Scripted Importer to import them into Unity, construct the arrays in the ScriptableObject, and fill in their values.



                  https://docs.unity3d.com/Manual/ScriptedImporters.html







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 24 at 8:31









                  Leo Bartkus

                  831411




                  831411






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237680%2fpopulate-scriptable-objects-automatically%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Schultheiß

                      Liste der Kulturdenkmale in Wilsdruff

                      Android Play Services Check