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

[BUG] ImGui window shows up even when _isOpen is false #71

Open
ArnaudDroxler opened this issue Oct 31, 2024 · 1 comment
Open

[BUG] ImGui window shows up even when _isOpen is false #71

ArnaudDroxler opened this issue Oct 31, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@ArnaudDroxler
Copy link

ArnaudDroxler commented Oct 31, 2024

Describe the bug
Hello,

I’m experiencing an issue with the integration of ImGui in my Unity project. I have a script using UImGui, and even when I set the p_open variable to false, the window still appears. And when i click the top right cross for closing the windows, the windows stay open (the windows blink ).

To Reproduce
Steps to reproduce the behavior:

  1. Create a new scene
  2. Add SampleDemoWindow
  3. Attach linked script to SampleDemoWindow
  4. Setup UImGui script (Render feature, camera )
  5. Play
  6. The window should be close but it appears

Version/Branch of UImGui:
Version: 5.0.0

Unity Version
2022.3.19f1

Render pipeline (HDRP / URP / Built-in)
URP

Expected behavior
The window should not be displayed when p_open is set to false.

Standalone, minimal, complete and verifiable example:

using UnityEngine;
using ImGuiNET;
public class TestUImGUI : MonoBehaviour
{
	[SerializeField]
	private UImGui.UImGui _uimGuiInstance;
    private bool _isOpen = false;

	private void Awake()
	{
		if (_uimGuiInstance == null)
		{
			Debug.LogError("Must assign a UImGuiInstance or use UImGuiUtility with Do Global Events on UImGui component.");
		}

		_uimGuiInstance.Layout += OnLayout;
	}

    private void OnLayout(UImGui.UImGui obj)
    {

        _isOpen = false;
        if (!ImGui.Begin("Test Window", ref _isOpen))
        {
            ImGui.End();
            return;
        }

        ImGui.Text("Hello, World!");
        ImGui.End();
    }

	private void OnDisable()
	{
		_uimGuiInstance.Layout -= OnLayout;
	}
}
@ArnaudDroxler ArnaudDroxler added the bug Something isn't working label Oct 31, 2024
@charlietran
Copy link

I believe this may just be an incorrect example in the repo. Looking at the official example from the ImGui.NET library used by uimgui, ImGui.Begin will always return true if the command executed successfully, and then assign closed status to the _isOpen bool which needs to be checked separately.

https://github.com/ImGuiNET/ImGui.NET/blob/master/src/ImGui.NET.SampleProgram/Program.cs#L116-L124

            if (_showAnotherWindow)
            {
                ImGui.Begin("Another Window", ref _showAnotherWindow);
                ImGui.Text("Hello from another window!");
                if (ImGui.Button("Close Me"))
                    _showAnotherWindow = false;
                ImGui.End();
            }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants