- Home /
Instantiated Component not Cloning Parent Classes?
When I call MyComponent c = Instantiate( MyComponent ) as MyComponent;
it does not clone any of the values inside of MyComponent's parent classes.
To clarify, I have my class order structure set up like this:
BaseClass--------------------------------------------------->Top Level Class
MonoBehaviour->MyBaseClass->MyMiddleClass->MyComponent
So, none of the variables from MyBaseClass or MyMiddleClass are being carried over when doing an Instantiate on the top level MyComponent
class (aka, my component that is exposed in the Inspector).
Does anyone know if this is expected Unity behavior? For example, I know that Unity does not ever expose parent class's public variables in the inspector (and this seems to be by design).
I know for Unity to clone private variables I had to tag them with [SeriliseFeild]. Not sure if that will work in you case.
Answer by tylo · Jul 14, 2014 at 06:50 PM
BoredMormon's comment did fix the problem. It turns out that the base classes just had no public variables. I had to insert [SerializeField] above all of my private methods in the base classes, and they were cloned just fine.
Your answer
