GameObject.Instantiate not using real time values?

So I’m having a problem with cloning a GameObject. I have something that emits a projectile, like a bullet. This projectile contains information that I pass on to the enemy I hit. Yes, I know what Raycasting is. Yes, this is exactly how I want to do it. I want to clone an existing projectile, then fire that clone at an enemy, then have collision detection destroy the clone.

CurrentProjectile = GameObject.Instantiate(Projectile) as GameObject; if (CurrentProjectile.GetComponent<VerboseProjectile>() != null) { CurrentProjectile.GetComponent<VerboseProjectile>().IsActive = true; } CurrentProjectile.name += System.Guid.NewGuid().GetHashCode(); WoundingProjectile wounding = CurrentProjectile.GetComponent<WoundingProjectile>(); WoundingProjectile wounding2 = Projectile.GetComponent<WoundingProjectile>();

In the above example, wounding.Wounds = List with a count of 1 and wounding2.Wounds = null.

Here’s what the List declaration looks like

public List<Wound> Wounds;

It’s just a public field.

So here’s a wrinkle - Wounds is not set in the Editor. Wounds changes at runtime. Does GameObject.Instantiate not care about the current state of the object? Does it only keep track of state at Awake/Start?

Maaan it just dawned on me that’s probably the case. But whyyyy argh.

Is there any way to force GameObject.Instantiate() to look at the current state of the object that it’s cloning?

Just as an aside, I know I have specific types in there, but those are for debugging. Ideally, this component does not KNOW what kind of Projectile it’s dealing with. I need it copy all the current fields of the Projectile it’s cloning without having to know what all of those fields are, at runtime. Thoughts?

Yeah, you have to copy the current state over to the clone yourself. There’s been work on doing that generically, I think it deals with Reflection. There is a Component Copier in the Asset Store I don’t know if it has source, but it might be an inspiration for a runtime component copier.