- Home /
The question is answered, right answer was accepted
Calling Unity functions in an inherited class?
My base class inherits from MonoBehaviour and the inherited class inherits from the base class. Is it possible to call methods like FixedUpdate in the inherited class? I.e.
Class BaseClass : MonoBehavior{}
class InheritedClass : BaseClass{
void FixedUpdate()
{
print("Is this possible?");
}
}
Have you tried it? $$anonymous$$aybe you should try it.
$$anonymous$$onobehavior classes are quite special... not sure you can do that. As a personal suggestion, whenever I "need to inherit" from $$anonymous$$onoBehavior, I create a main $$anonymous$$onoBehavior wrapper class, and I add the rest of the component as custom classes. Then I use the $$anonymous$$onoBehavior wrapper just a like a master control for the rest of the components.
Regards
Answer by meat5000 · Feb 27, 2015 at 12:20 AM
If something Inherits from MonoBehaviour it has all MonoBehaviour gubbings and whatever you add in. What would be the point of inheritance otherwise?
using UnityEngine;
using System.Collections;
public class SomeBase : MonoBehaviour {
public float test1 = 0.0f;
}
using UnityEngine;
using System.Collections;
public class SomeInherited : SomeBase{
void FixedUpdate()
{
print("Is this possible?");
}
}
][1]
It probably took you longer to write this question than it would have taken you to try it.
Silly mistake on my part - caught it and forgot to take down the question. I didn't create an instance of SomeInherited lol. Thanks for the answer anyways.