How can I instantiate a object with a constructor?

I created a constructor for my NPCs. I struggle with instantiating them (as a gameobject) via the constructor with its own health etc. And what can I do, to set for each instantiated Gameobject NPC the health etc? I want to something like this: Instantiate(NPC[0], NPC[0].Position, NPC[0].Rotation). I want to Instantiate a prefab with its health etc from the constructor. I cant change the properties from the array of NPC constructors in the inspector, so i need to do it by code.

NPC constructor:

    public class NPC : Obstacle
        public bool HasPath { get; set; }
        public GameObject Path { get; set; }
        public NPC(float hp, int id, Vector3 position, Quaternion rotation,GameObject prefab, bool hasPath, GameObject path) : base(hp, id, position, rotation, prefab)
            HP = hp;
            ID = id;
            Position = position;
            Rotation = rotation;
            HasPath = hasPath;
            Path = path;
            Prefab = prefab;
        public void CreateNPC()
            Instantiate(this.Prefab, this.Position, this.Rotation);

A variant of the answer above is that you can skip the extra classes and just Init the Instantiated object directly.

public class GameLevel : MonoBehaviour
    //drag your prefab with Enemy-script
    //attached to this var in the Inspector
    public Enemy oEnemyObjBase;

    //List<Enemy> aEnemyList;

    void BuildLevel()
        Enemy oEnemy = Instantiate(oEnemyObjBase, this.transform);
        //aEnemyList.Add(oEnemy); //you can also save the enemy in a list for easy access

public class Enemy : MonoBehaviour
    float fHealth;
    public void Init(float health)
        fHealth = health;

If you have NPC objects with custom values, and you want to instantiate gameobjects with those NPC components, you could use something like this:

GameObject go = Instantiate(this.Prefab, this.Position, this.Rotation);

Since I cannot control the constructor, I use the Setup() method to set the values. As a parameter, I would use another NPC object, and basically copy the values from it.

public void Setup(NPC npc)
   HP = npc.HP;
   ID = npc.ID;

Hey, I just found this article.
It basically say that you can create a object with the variables and then instantiate it.


you can disable script through editor and after initialisating enable again :

GameObject CrushedSprite = Instantiate(SpritesStorage.Instance.CrushedSprites[x], V3Pos, Quaternion.identity);
CrushedSprite.GetComponent<CrushedBehavior>().Setup(Direction, Speed);
CrushedSprite.GetComponent<CrushedBehavior>().enabled = true;