- Home /
I have a class of a class, but the first class isn't updating
So, I have the monobehavior BaseUnit, a class of BaseUnit called MobileUnit, and a class of MobileUnit called ShipFafher. Both MU and SF have in their void Update base.Update(). A SF script, however, will execute the SF and BU Updates, but not the MU. So that's my problem, I need the middle man to cooperate.
Answer by RodrigoAbreu · Feb 07, 2021 at 11:06 PM
SF should declare public override void Update not public void Update. Just an example, I'm not sure which accessibility modifier you're using. If still not cascading the override for all the child classes, do so.
I'm afraid it didn't work. It gave the error: error CS0506: 'ShipFather.Update()': cannot override inherited member 'BaseUnit.Update()' because it is not marked virtual, abstract, or override I changed BU Update to the only version it wouldn't give another error, public virtual void Update, and it still didn't work. But I found the error, so even though I'm feeling stupid, thanks for your time. $$anonymous$$U Update was private.
public class BaseUnit : $$anonymous$$onoBehaviour
{
protected virtual void Update()
{
}
}
public class $$anonymous$$obileUnit : BaseUnit
{
protected override void Update()
{
base.Update();
}
}
public class ShipFather : $$anonymous$$obileUnit
{
protected override void Update()
{
base.Update();
}
}
Your answer

Follow this Question
Related Questions
Return a value from a custom class 3 Answers
Need assistance with SubType in custom class (UnityScript or C#) 2 Answers
NullReferenceException and script load order 1 Answer
Array of a class deleting previous array element 1 Answer
Getting NullReferenceException when creating class instance using List 1 Answer