Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# code for custom MainLoop missing critical attribute #8799

Closed
PastTheFuture opened this issue Jan 20, 2024 · 0 comments · Fixed by godotengine/godot#88635
Closed

C# code for custom MainLoop missing critical attribute #8799

PastTheFuture opened this issue Jan 20, 2024 · 0 comments · Fixed by godotengine/godot#88635
Labels
area:class reference Issues and PRs about the class reference, which should be addressed on the Godot engine repository bug topic:dotnet
Milestone

Comments

@PastTheFuture
Copy link

Your Godot version: 4.2

Issue description:
C# code for MainLoop page missing critical attribute. As per this commit, in order for Godot to see your custom C# MainLoop, it needs to have the [GlobalClass] attribute. Without this attribute you get the message: "Error: MainLoop type doesn't exist: CustomMainLoop".

URL to the documentation page:
https://docs.godotengine.org/en/stable/classes/class_mainloop.html

Proposed code:

using Godot;

[GlobalClass]
public partial class CustomMainLoop : MainLoop
{
    private double _timeElapsed = 0;

    public override void _Initialize()
    {
        GD.Print("Initialized:");
        GD.Print($"  Starting Time: {_timeElapsed}");
    }

    public override bool _Process(double delta)
    {
        _timeElapsed += delta;
        // Return true to end the main loop.
        return Input.GetMouseButtonMask() != 0 || Input.IsKeyPressed(Key.Escape);
    }

    private void _Finalize()
    {
        GD.Print("Finalized:");
        GD.Print($"  End Time: {_timeElapsed}");
    }
}
@skyace65 skyace65 added topic:dotnet area:class reference Issues and PRs about the class reference, which should be addressed on the Godot engine repository labels Jan 25, 2024
@akien-mga akien-mga added this to the 4.3 milestone Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:class reference Issues and PRs about the class reference, which should be addressed on the Godot engine repository bug topic:dotnet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants