EditorGUILayout Array

I’ve been trying to fill a Transform array using the EditorGUILayout but it won’t let me put any object in from either the project folder or the Hierarchy.

		if(obstacleProperties._obstacleType!=ObstacleScript.ObstacleType.None)
		{
			obstacleProperties.participantCount = EditorGUILayout.IntField("Amount of Participants:", obstacleProperties.participantCount);
			if(obstacleProperties.participantCount>0&&obstacleProperties.participantCount<=100)
			{
				obstacleProperties.participants=new Transform[obstacleProperties.participantCount];
				for(int c=0;c<obstacleProperties.participantCount;c++)
				{
					obstacleProperties.participants[0]=(Transform)EditorGUILayout.ObjectField("Participant:",obstacleProperties.participants[0],typeof(Transform));
				}
			}
		}

I’ve been doing the same things with just single Transforms and then it works like a charm. Everything in the array works, except for dragging the objects in. Does anyone know how I would be able to fix this?

Thanks in advance,
Tim

When you say

obstacleProperties.participants=new Transform[obstacleProperties.participantCount];

you’re redeclaring your array, so it’s empty. Only do this when the array size actually changes, and make sure you copy the contents of the old when when you do.

You can check if the size has changed by comparing your obstacleProperties.participants value to the current obstacleProperties.participants array’s length.