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

Mono plugins events being called at the wrong times #30734

Closed
richard-hajek opened this issue Jul 21, 2019 · 2 comments
Closed

Mono plugins events being called at the wrong times #30734

richard-hajek opened this issue Jul 21, 2019 · 2 comments
Labels

Comments

@richard-hajek
Copy link

richard-hajek commented Jul 21, 2019

Godot version:
Godot Engine v3.1.1.stable.mono.official

OS/device including version:
Output of uname -a:
Linux laptop 5.2.1-arch1-1-ARCH #1 SMP PREEMPT Sun Jul 14 14:52:52 UTC 2019 x86_64 GNU/Linux
Running Arch Linux with Godot-Mono from AUR

Issue description:
While making C# plugin I have encoutered:
_Ready(), _EnterTree(), _ExitTree() being called even in the editor itself.
_Init() never called, even after game starts.

Steps to reproduce:

  1. Create a plugin with a following script:
using Godot;

[Tool]
public class NodeScript : Node
{

    public override void _EnterTree()
    {
        GD.Print("Node _EnterTree()");
    }

    public NodeScript()
    {
        GD.Print("Node constructor");
    }

    public override void _Init()
    {
        base._Init();
        GD.Print("Node _Init()");
    }

    public override void _Ready()
    {
        base._Ready();
        GD.Print("Node _Ready()");
    }

    public override void _ExitTree()
    {
        GD.Print("Node _ExitTree()");
    }
}
  1. Enable plugin and add the custom node.

  2. Rebuild project

  • You will now notice that these prints happen in the editor itself, not even in the game.
  1. Start project
  • You will notice that _Init() is never called. Constructor is called sometimes 3 times and sometimes once.

Minimal reproduction project:

New Game Project.zip

@neikeq
Copy link
Contributor

neikeq commented Jul 21, 2019

_Ready(), _EnterTree(), _ExitTree() being called even in the editor itself.

This is the expected behaviour, isn't it? The [Tool] attribute means "run in the editor". If you've added the node to your tree in the editor, these functions will be called. This is the same in GDScript.

_Init() never called, even after game starts.

_Init() was never implemented in C#, and I removed it completely on latest master. _init() is simply a constructor in GDScript, so the equivalent in C# is a constructor as well.

Constructor is called sometimes 3 times and sometimes once.

These are most likely temporary instances the editor needs to create in order to get the default values of exported fields. I plan to improve this so that you can at least know when this happens (probably via a specialized constructor overload).

@richard-hajek
Copy link
Author

Oh you are correct, sorry for the misunderstanding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants