- Home /
Are multidimensional arrays supported in UNET?
Ive run into some strange behaviour writing my inventory system.
An integer array with a total length of 48, first dimension being 24 indexes long and second dimension being 2 indexes long, became an array with a total length of 48, 48 first dimension, 0 second dimension. This lead to some frustrating problems, since I couldnt find any documentation about it and kept getting null reference exceptions trying to access an element using multiple indexes on a now one dimensional array. Did I miss something or am I doing something wrong?
This only seems to happen using UNET.
Answer by Orami · Jun 20, 2016 at 10:01 PM
Yes, they should be supported as long as you are using native types. If it is causing an issue you could always do something like:
inventory[x+(y*24)] which would make it to your inventory[24][2] layout...
Is an integer a "native type"? (Never heard of those before, are those the same as primitives?) If it is it should work, but since it doesnt its either my code thats not working or you are wrong (no offence). Can you give me any evidence or documentation backing your post up? Again, I dont want to offend you, but its really hard to differientiate between false statements and actual solutions on the internet. How is inventory[x+(y*24)] supposed to work btw? I dont get how that would make it to my layout, please explain. I am trying to create my own workaround right now, but since I havent found a real solution yet i still hope you can help.
int, float, char, string, double. I probably thought primitive, but typed native. You can't sync an enum, but you can sync a struct or a class if it contains only those primitive types.
[Serializable]
public class BaseCharacterInfo //syncs ok
{
public int STR;
public int INT;
public int WIS;
public int DEX;
public int CON;
public int allocPoints;
public int HP;
public int xHP;
}
[Serializable]
public struct Spell //will not sync
{
public string name;
public GameObject go;
public spellType Type;
}
Why it works: I assume you have 2 rows each with 24 elements. So each row has 0...23 elements.
Here is a 2d array in an image this might be more help than me trying to type out a long explanation (having issues using the image insert... give me a moment here is a link)
Your answer
Follow this Question
Related Questions
Unet assigning local player Authority to a gameObject. 1 Answer
Store multiple sprite in code C# 0 Answers
Change color of the object based on previous player's choice 0 Answers
Multiple Cars not working 1 Answer
Array foreach problem 1 Answer