You can’t Instantiate a Weapon (though you could instantiate a weaponModel). What are you actually trying to do? Sounds to me like you want to create a prefab with a “Weapon” script attached, but you’re not.
Also, it’s not GameObject.Instantiate(), it’s Object.Instantiate(). No point in climbing down that tree.
Sorry for the mistake.
Actually, what I am trying to do is calling Object.Instantiate(weaponModel) somewhere in Weapon class (but not in constructor). Weapon class is not a child of MonoBehaviour, and I don’t want to attach it to a game object.
In fact, when I point to Weapon class in project hierarchy, the inspector shows the public field weaponModel, and I drag my prefab there. But initialization doesn’t work at runtime
I was suggesting you upload a unitypackage with only the relevant items. What you’ve shown so far does not describe the flow of your code, or what is serialized. For example, where did you get yourGunModelPrefab? This line should be where the problem lies.
Thanks for efforts. I managed to make a work around. I made my Weapon class inherit from MonoBehaviour, and attached my Weapon’s subclass to empty game object. It seems that scripts cannot be assigned components from inspector unless they are actually in scene hierarchy and attached to some game object ← Correct me if this is wrong
I’m not sure, but I wouldn’t be surprised; it probably wouldn’t know how to construct an instance. Or more likely, you’d be trying to assign the type of the script and not an instance of itself.