Does GameObject.GetComponent() find sub classes?

Go To StackoverFlow.com

1

Working in the latest Unity3d 3.5 if it matters.

If I have a set of classes:

Class A extends MonoBehaviour
Class B extends Class A
Class C1 extends Class B
Class C2 extends Class B

And I have a GameObject that has C2 as a component. Will GetComponent.<A>() return the C2 component?

2012-04-03 21:32
by Chris


1

Well, I haven't tried a three-level hierarchy but, for two, I can confirm that GetComponent works as you expect.

2012-04-05 08:15
by Talemon


0

Also, this can be helpful: try to call

gameObjC1.SendMessage("MethodFromA");

in case you need to get A just to call its method.

2014-11-12 14:57
by Vitalii Vasylenko
Ads