Make it once as a prefab. Clone it forever.

The problem
Assembling it by hand.
var go = new GameObject();go.WorldPosition = origin;var model = go.Components.Create<ModelRenderer>();var body = go.Components.Create<Rigidbody>();go.Components.Create<Projectile>();// ...and every setting, in code
Every model, collider and setting lives in code. Changing how the bullet looks means recompiling.
The fix
Build it once in the editor.
Save the finished object as a prefab. In code, just make copies of it.
prefab→Clone()→new copy
The fix in code
A slot and one call.
[Property] public GameObject ProjectilePrefab { get; set; } void Fire( Vector3 origin, Rotation aim ){ var go = ProjectilePrefab.Clone( origin, aim );}
Drag the prefab into the slot. Clone places a copy at a position and rotation.
Watch out
Copies don't clean themselves up.
TimeSince _alive; protected override void OnUpdate(){ if ( _alive > 5f ) GameObject.Destroy();}
Every clone stays in the scene until it's destroyed. A missed bullet flies forever.
The rule
Design in the editor. Clone in code.
- Make it
- a prefab
- Spawn it
- Prefab.Clone( pos, rot )
- Clean it up
- GameObject.Destroy()