.getComponent() creates an Instance?

Hi,

I am trying to acess an function from a script which is attached to an Gameobject.
There is no problem with that.

Here is the call:

m_goTurtleSpawner.GetComponent<TurtleSpawner().getTurtleForDamage();

This function gets called. I am looping through a for-loop within this function. There is
my problem. The size of the array is always 0.

for (int i = 0; i < m_lTurtles.Count; i++)
{
     ...Some Stuff...
}

I am logging the size of the array everytime an “enemy” spawns and the numbers are correct.

So my question is if there is the posibility that the getComponent() function creates a new reference? Then it would be clear, that the array is empty.

Thanks :slight_smile:

No, GetComponent will not create anything. It can only return components that already exists. If there isn’t such a component it will return “null”.

You posted two very small code-snippets which aren’t really connected. I guess that your getTurtleForDamage function returns the m_lTurtles array, so you should search for the problem there.