- Home /
Using an UpdateManager in combination with inputs (issue)
Hi. I'm currently experiencing a strange issue. I have extracted the relevant code into a standalone project and the issue still occurs. I am using an UpdateManager as opposed to all of my components having their own Update. In one of my components I use the pseudo-update method to poll for input and destroy the object. However, not all of the objects are deleted. The code is as follows:
public class UpdateManager : MonoBehaviour
{
void Update()
{
for (var i = 0; i < ManagedBehaviour.updateTick.Count; i++)
{
ManagedBehaviour.updateTick[i].Tick();
}
}
}
ManagedBehaviour:
public class ManagedBehaviour : MonoBehaviour
{
public static List<ManagedBehaviour> updateTick = new List<ManagedBehaviour>();
protected virtual void OnEnable()
{
updateTick.Add(this);
}
protected virtual void OnDisable()
{
updateTick.Remove(this);
}
// Declare the method that will be called in the UpdateManager
public void Tick()
{
OnTick();
}
protected virtual void OnTick() { }
}
Employee:
public class Employee: ManagedBehaviour
{
protected override void OnTick()
{
if (Input.GetKeyDown(KeyCode.Z))
{
Debug.Log("The code was reached in object " + name);
Destroy(gameObject);
}
}
}
The strange thing is, if I have multiple instances of Employee attached to different GameObject in the scene, not all of the objects are deleted. Even stranger, if I only include a Debug message as opposed to invoking Destroy() when 'Z' is pressed, all of the objects correctly display the debug message. However, if I include both the Debug.Log and the Destroy() calls the issue occurs. This would imply that, for whatever reason, Destroy() is the culprit of the issue. I have tried many tests, all of them point to Destroy() as being the issue. Can anybody shed some light on what might be happening?
Your answer
Follow this Question
Related Questions
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers
New input system and Scene Manager 0 Answers
Tiled Movement Inputs are Inaccurate 1 Answer
Trouble with changing the sensitivity of an axis 0 Answers
Input Problems 2 Answers