TheCherno / Hazel

Hazel Engine
Apache License 2.0
11.64k stars 1.5k forks source link

Scene hierarchy won't show "Create Empty Entity" menu! #562

Closed VagueLobster closed 2 years ago

VagueLobster commented 2 years ago

Describe the issue (if no issue has been made)

Currently with the code used in Hazel 2D, and when launching Hazel 2D, you can't get the "Create Empty Entity" to pop up.

This bug is ONLY happening when you haven't loaded a scene OR created a new scene!

Impact Issue/PR
Issues this solves None or #number(s)
Other PRs this solves None or #number(s)

Proposed fix _(Make sure you've read [on how to contribute])

By adding: m_SceneHierarchyPanel.SetContext(m_ActiveScene); after m_ActiveScene = m_EditorScene; inside OnAttach() in EditorLayer.cpp right-clicking to display the menu works again!

Steps to reproduce the bug: 1: open up Hazel 2D. 2: Move mouse cursor over to the Scene hierarchy. 3: Right-click and see that the "Create Empty Entity" won't pop up.

erikrl2 commented 2 years ago

Hey, I would suggest calling NewScene() at this point, replacing this block in OnAttach():

m_EditorScene = CreateRef<Scene>();
m_ActiveScene = m_EditorScene;
m_SceneHierarchyPanel.SetContext(m_ActiveScene);

with: NewScene();

This would however need a improvement/refactor of NewScene() that would look like:

void EditorLayer::NewScene()
{
    if (m_SceneState != SceneState::Edit)
        return;

    m_EditorScene = CreateRef<Scene>();
    m_EditorScene->OnViewportResize((uint32_t)m_ViewportSize.x, (uint32_t)m_ViewportSize.y);
    m_SceneHierarchyPanel.SetContext(m_EditorScene);

    m_ActiveScene = m_EditorScene;

    m_EditorScenePath = std::filesystem::path();
}

This also fixes the following other issues:

I currently have this fix on my Hazel fork, so I could just open a PR to your fork(?) (would need some conflict resolving) or should I rather open a new PR?

VagueLobster commented 2 years ago

Hey, I would suggest calling NewScene() at this point, replacing this block in OnAttach():

m_EditorScene = CreateRef<Scene>();
m_ActiveScene = m_EditorScene;
m_SceneHierarchyPanel.SetContext(m_ActiveScene);

with: NewScene();

This would however need a improvement/refactor of NewScene() that would look like:

void EditorLayer::NewScene()
{
  if (m_SceneState != SceneState::Edit)
      return;

  m_EditorScene = CreateRef<Scene>();
  m_EditorScene->OnViewportResize((uint32_t)m_ViewportSize.x, (uint32_t)m_ViewportSize.y);
  m_SceneHierarchyPanel.SetContext(m_EditorScene);

  m_ActiveScene = m_EditorScene;

  m_EditorScenePath = std::filesystem::path();
}

This also fixes the following other issues:

  • When you try to open a new scene while playing/simulating, Hazelnut crashes.
  • When you start Hazelnut, open a new scene, add entities, press play/simulate, the empty m_EditorScene gets copied to m_ActiveScene, causing loss off all progress.

I currently have this fix on my Hazel fork, so I could just open a PR to your fork(?) (would need some conflict resolving) or should I rather open a new PR?

Erhm, i think it's better to just wait and see what @TheCherno has to say about this 🙂