Multidimensional arrays of differing types?

I suspect that this isn’t really a thing I can do, but is it possible to have a multidimensional array with different types of variables? i.e, one dimension is ints, another is strings.

If not, what is the most reasonable way to simulate this effect?

I’m creating a class that will use a list of references to some game objects (or rather, instances of scripts placed on those game object) and also to have an int value associated with each of those.
Offhand, I could simply create two arrays, one for the scripts and one of ints. It’s not exactly hard or complicated. But I do want to make sure I keep those organized properly. It would be really nice if I could make sure that an int value I adjust is the same one associated with a given script instance. If I’m jumping back and forth between two arrays in the inspector, it’s going to become hard to keep track of which value is which, especially when those arrays start getting long.

Why not encapsulate the values you need into a class or struct and use a list of those instead?

1 Like

Because it’s late at night and I’m too tired to remember that stuff like that exists.

1 Like

All good mate. I’ll be the first to suggest you should preference sleep over coding. ;p

1 Like

If all possible values are unmanaged structs, then you can also create a union

using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Explicit)]
struct MyUnionType
{
    [FieldOffset(0)]
   public byte byteValue;

   [FieldOffset(0)]
   public int inValue;

   [FieldOffset(0)]
   public float floatValue;

   [FieldOffset(0)]
   public long longValue;

   [FieldOffset(0)]
   public short shortValue;

   [FieldOffset(0)]
   public double doubleValue;
}