Adding an item to a Generic List copies the old one

Hi,
I have a public List containing a pair of information:

public List<EntityMethodPair> targets = new List<EntityMethodPair>();

The subclass for the EntityMethodPair class looks like this:

public class EntityMethodPair {
	public Entity target;
	public string method;	
}

This works fine and I can add new items in the inspector, but,
the old values always getting copied.

So if I put an entity named “a” in the target of item 0 and resize the list to 1,
the new entry also will have “a” and the exact values like item 0.

Is there a trick so adding new things in the inspector will be empty things?

There is no way to get it to stop this behavior, apart from creating a custom inspector or property drawer for your list. The default inspector will always copy the old value.

Because it’s so systematic, when you want empty indexes, just make sure the last value is of the type you want to duplicate before you increase the size. In this case the last value should be empty.