Assigning Tag and Animators to New Instantiated Object

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class WillSpawn : MonoBehaviour
{
    public GameObject SpawnObject;
    //public bool shouldSpawn = false;
    public float spawnTime;
    public float spawnDelay;
    public int timestoSpawn = 0;


    // Start is called before the first frame update
    void Start()
    {
        InvokeRepeating("Spawn_Obj", spawnTime, spawnDelay);
    }

    // Update is called once per frame
    void Update()
    {
       
    }

    void Spawn_Obj()
    {
       
        SpawnObject= Instantiate(SpawnObject, transform.position, transform.rotation);
        SpawnObject.tag = "Creature";
        timestoSpawn++;
        //if(shouldSpawn)
        if(timestoSpawn == 1) 
        { CancelInvoke("Spawn_Obj"); }
    }
}

Hi,

I know GameObject tags can be assigned at run-time but my cloned objects don’t have the tag “Creature”. How can I go about instantiating them with this tag?
Additionally, how can I assign them an animator when they are instantiated?

Thank you!

Does the tag exist in the project “Tags & Layers” window?

I’m also pretty sure you need to cast the object that Instantiate returns into a GameObject, aren’t you getting a compiler error?

either

        SpawnObject= (GameObject) Instantiate(SpawnObject, transform.position, transform.rotation);

or

        SpawnObject= Instantiate(SpawnObject, transform.position, transform.rotation) as GameObject;

edit: about the animator, if you already have a the component attached on the object you can get it like so

GetComponent<Animator>();

if you need to cache it just save it as a class variable.

if you want to add one dynamically you can use “AddComponent”

AddComponent<Animator>();