Spawning a Prefab after 50 seconds not working entirely correctly.

This is my current Code for Spawning the prefab after 50 seconds the prefab spawns but the game crashes straight after.

using UnityEngine;
using System.Collections;

public class BossSpawn : MonoBehaviour
{
    public GameObject Boss;
    GameObject bossClone;

    void Start ()
    {
        StartCoroutine(WaitSpawner());
    }

    IEnumerator WaitSpawner()
    {
        yield return new WaitForSeconds(50f);
        Debug.Log("it has been 50sec");
        bossClone = Instantiate(Boss, transform.position, Quaternion.identity) as GameObject;
    }   

    void Update () {
   
    }
}

This is the Error I get
UnassignedReferenceException: The variable Boss of BossSpawn has not been assigned.
You probably need to assign the Boss variable of the BossSpawn script in the inspector.
UnityEngine.Object.Internal_InstantiateSingle

thank you for any help!

Well the error is pretty explicit. you want to spawn whatever is in the Boss variable, but it is not assigned. so trying to spawn it crashes.

Heya, thank you for the help! It is the first time I have coded so I am very much a beginner. When you say Assign do you mean assigning the Tag Boss to the Prefab? Or do you mean something else?

In the editor, in the inspector panel you should have a field labeled boss. You need to drag a gameobject into that field.

I have done that. The Boss spawns at 50 seconds the moment it spawns however the game crashes.

2871438--210404--screen.JPG

In that case, could there be more than one bossspawn in your scene?

A somewhat hackish fix would be to check if boss is properly assigned before attempting the spawn.

If(boss != null)
//Your instantiate code

Thank you so much JC that got it to work. If it isn’t any trouble could ask why that line of code worked?

Like I said, it is hackish.
What it does is validate if the attribute boss has been assigned before attempting to spawn it.
The non-hack fix would be to figure out why you have a gameobject attempting to spawn a boss without the attribute being assigned.