Calling the default base method of overrides in c#

Good day, all.

When working with c# in VS2022, IntelliSense automatically generates base calls for overrides.

Do these have any use or can they be safely removed?

For example:

public override void _UnhandledInput( InputEvent @event )
{
	base._UnhandledInput( @event );
}

Thanks.

Hello. yes you can safely remove it.

The sample code in link does not call the base method.

public override void _UnhandledInput(InputEvent @event)
{
    if (@event is InputEventKey eventKey)
        if (eventKey.Pressed && eventKey.Keycode == Key.Escape)
            GetTree().Quit();
}

If your base class has overridden method (with some logic), note that maybe you want call base method.

More about overriding method in C#

1 Like

Thank you for the quick reply.

Any idea if this has anything to do with:

C# _UnhandledInput(…) Memory Leak · Issue #30821 · godotengine/godot (github.com)

I am using 4.2.2 and I have observed the same problem. Thousands of objects are created and never seemingly disposed of even if the method contains no more than the base call (or nothing whatsoever).

Never mind.

Even _Process() does this too.

There must be something fundamental that I fail to understand.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.