2D array with GameObject and Float

Hi people of Unit.

I whould like to make an 2D array visible in the inspector so I can drag GameObjects in it(go#) and write a float value (relatieveFactor#) so I can use those later in the script.
It should look like I show you below, but I ceep failing. I think I mix all the information a searched on the web.

Objecten
size
element1
go1
relatieveFactor1
element2
go2
relatieveFactor2
…

This is the code i’ve got for it:

[System.Serializable]
public class Objecten
{
    public GameObject element;
    public float relatieveFactor;
}


public class CubeMaker : MonoBehaviour {
    public Objecten[,] parts = new Objecten[GameObject ,float 1.0]; //default float = 1.0
    ...

Or do I need to use get and set for it?
I hope you can help me and thanks for your time.

Unity doesn’t serialize multi-dimensional arrays.

So it’s not going to show up in the editor.

Furthermore:

public Objecten[,] parts =new Objecten[GameObject ,float1.0];

THAT is NOT how you create an array.

I think you mean to have a one dimensional of a data structure that is made up of 2 distinct values. One typed GameObject, one typed float.

Try something like this:

public class CubeMaker : MonoBehaviour
{
    public Objecten[] parts;
}

Objecten defines the two values for you, the array is just of those Objectens.

Note, you’d set the default value for ‘relativeFactor’ in the class its in, but just as I brought in this other thread:

default values don’t work for array elements as you might expect… it’s just the way the serializer works. So you’re not going to get to default the factor to 1f quite the way you want.

I’ll try to work with your information.
Thanks for your time and effort.