- Home /
Question by
Igorotak · Nov 08, 2020 at 04:01 AM ·
classupdate functionabstract
How to run Update() from an abstract class?
I have an abstract class that checks if a Structure is being built. It works if I run it from the child class but when when it's in the parent class, the debug wont even print anything. Any ways to fix it?
protected void UnderConstruction()
{
int n = 0;
Debug.Log("Under Construction");
if (builders[buildingConstructor - 1] == null) //Check if builders array is full
{
foreach (Thinbloods worker in PopulationManager.peasants)
{
if (builders[buildingConstructor - 1] != null) //Break for loop if builders array is full
{
break;
}
if (!worker.IsWorking())
{
builders[n] = worker;
}
Debug.Log(builders.Length + "******");
}
}
}
void Update()
{
Debug.Log("@@@");
if (isBeingConstructed)
{
UnderConstruction();
isBeingConstructed = false;
}
}
Comment
Answer by jackmw94 · Nov 08, 2020 at 06:49 PM
If you are overriding Update then the child classes function will completely replace the parent class function. You can still call the parent class Update function manually with base.Update();
If this isn't the problem then can you give more information about your class structure and what object you're calling the function on?