Populate Scriptable Objects Automatically











up vote
0
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

















This question has an open bounty worth +50
reputation from Spyros ending in 4 days.


This question has not received enough attention.
















  • 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
    2 days ago










  • 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
    2 days ago






  • 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
    yesterday










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















up vote
0
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

















This question has an open bounty worth +50
reputation from Spyros ending in 4 days.


This question has not received enough attention.
















  • 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
    2 days ago










  • 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
    2 days ago






  • 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
    yesterday










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













up vote
0
down vote

favorite









up vote
0
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

361213




361213










asked Nov 10 at 9:38









Spyros

23.2k1970110




23.2k1970110






This question has an open bounty worth +50
reputation from Spyros ending in 4 days.


This question has not received enough attention.








This question has an open bounty worth +50
reputation from Spyros ending in 4 days.


This question has not received enough attention.














  • 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
    2 days ago










  • 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
    2 days ago






  • 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
    yesterday










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


















  • 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
    2 days ago










  • 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
    2 days ago






  • 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
    yesterday










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
















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
2 days ago




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
2 days ago












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
2 days ago




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
2 days ago




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
yesterday




@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
yesterday












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




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












1 Answer
1






active

oldest

votes

















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











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

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








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

361213




361213










answered Nov 19 at 13:02









D Manokhin

586118




586118












  • 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


















 

draft saved


draft discarded



















































 


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

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith