How to create null which extended MonoBehavior included jagged array?

Hi there

I will create jagged array and initialize the array.
The variables are null but the type are the class which extended MonoBehavior".

like this

    {
        {null, null, null,...}
        {null, null, null,...}
        {null, null, null,...}
    }

I defined variable.

private Enemy[][] checkEnemyArray;

it is the code i did.

        int row = 30;
        int column = 40;

        checkEnemyArray = Enumerable.Range(0, row).Select(
            x => Enumerable.Range(0, column).Select(y => new Enemy()).ToArray<Enemy>()
            ).ToArray<Enemy[]>();

It works little nice but the warning occurred.

You are trying to create a MonoBehaviour using the 'new' keyword.  This is not allowed.  MonoBehaviours can only be added using AddComponent().  

but, I tried like this, I put null instead Enemy() but error occurred

        checkEnemyArray = Enumerable.Range(0, row).Select(
            x => Enumerable.Range(0, column).Select(y => null).ToArray<Enemy>()
            ).ToArray<Enemy[]>();

Could you tell me the good way?

If your “Enemy” extends Monobehavior and is intended to be a physical object within the game world, you need to Instantiate() it instead of using the new Keyword.

Paraphrasing your code is not ideal for users to help you, the error may be occurring in another area of your code that may not be apparent to you at first glance, posting the full class involved is more desirable.

I will do that without Linq…

        checkEnemyArray = new Enemy[row][];
        for(var i =0;i<row;i++){
            checkEnemyArray *= new Enemy[column];*

}