UnityEngine.GameObject.AddComponent(System.Type) unity addcomponent with constructor. (UnityUpgradable). Adds a component class named className to the game object. GameObject.AddComponent with string argument has been deprecated. Use AddComponent (Type) or the generic version instead. unity addcomponent Instead create the component as normal (without parameters), add the component to the gameobject, then call a setup method on the component that provides the necessary parameters and runs whatever code you currently have in the constructor. AddComponent . Use AddComponent (Type) or the generic version instead. Experience hands-on learning as you discover what’s possible with Unity and unlock free assets to support you in creating your best projects. //Use the AddComponent () Method to add a component to your gameobject GameObject gameObject; gameObject.AddComponent (); //Component has to be an … instantiate Automatic Constructor Selection | Unity Container Let’s create one solid color for our line to do that add these 2 lines to your code. MyComponent myComponent = AddComponent ("Initial Value"); Or at very least (trying to prevent horizontal scroll bars here): MyComponent myC = AddComponent("MyComponent", "Initial Value") as MyComponent; And, of course, allowing us to have as many parameters as we want, just like we would have on a regular constructor. You can use a factory pattern, where you … using UnityEngine; [ AddComponentMenu (" Transform /Follow . Use … Factory · UnityTechnologies/open-project-1 Wiki · GitHub InjectionProperty is derived from the InjectionMember Class. unity addcomponent public function AddComponent ( componentType : Type): Component ; public Component AddComponent (Type componentType ); This can cause performance impact, especially in loops. All your entities are designed as prefabs, with components that get wired together in the editor and saved with the prefab. You can do this in Unity by adding a TextAsset object to your script. So I'm using AddComponent to add a Rigidbody component to a cube in a scene. In addition, configurable as any other game object on your scene. I wonder if you could do something like make a private constructor, or some other decorator on the class itself that would prevent .AddComponent<>() from working except from within it.