- Home /
Inheritance Start ok, Update ko
Edit: can't delete the questions sorry, the problem was coming from my code (due to delay, start method is call after a method that should be executing after)
Hi there, I'm driving myself crazy. Took a look at other questions related to inheritance but didn't find the solution :/ I just want a simple inheritance model. Here is my code :
public abstract class Item : MonoBehaviour {
protected virtual void Start () {
print("basestart");
}
protected virtual void Update() {
print("baseupdate");
}
}
public class SubItem: Item {
protected override void Start () {
base.Start();
print("substart");
}
protected override void Update() {
base.Update();
print("subupdate");
}
}
The start process works ! But none of update method is called :/
How can i do this in Unity ? What is the good way to achieve this or the best practice ? Thanks for any help !
Answer by Berenger · Jun 08, 2012 at 07:55 PM
This is the good way. I created a new project, two c# files and pasted your class, attached SubItem to the camera and got the two update prints each frame.
Thx for your reply ! Damn it you're right. Any hint on why it is not working with the rest of my code classes ? I mean i could understand if the start method wasn't called but it is, why the update not ? (I've no warnings nor error) What in my code can interfere with the process ?
The component could be disabled, or not attached. If Item and SubItem are on the same file, I'm not sure which one the gameObject would pick. Probably the second one as the first is abstract. $$anonymous$$aybe your console has collapse enabled ?
Your answer
Follow this Question
Related Questions
toggle buttons 2 Answers
Character Contolller Hit 3 Answers
camera . smooth follow 1 Answer
Object refernce not set to an instance of an object .... 1 Answer
None (Physics Material) Properties 1 Answer