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

Components OnDisable and OnDestroy logic doesn't match OnAwake, OnEnable, and OnStart #295

Open
adriengivry opened this issue Dec 13, 2023 · 0 comments
Labels
Bug Something isn't working Refactoring Something that needs a refactoring

Comments

@adriengivry
Copy link
Owner

adriengivry commented Dec 13, 2023

Description
Currently, OnAwake, OnEnable, and OnStart are called by the Actor when a component is created during gameplay (m_playing is true), or when starting the scene, but OnDisable and OnDestroy are called by the component when the component gets destroyed (even if the game isn't playing).

Expected behavior
OnDisable and OnDestroy should only be called when a component gets removed during gameplay, or on actor destruction (i.e. gameplay stops/scene change...)
Also, only Actor should call the OnSomething() methods, so we should move this code out of the AComponent::dtor():

OvCore::ECS::Components::AComponent::~AComponent()
{
  if (owner.IsActive())
  {
    OnDisable();
    OnDestroy();
  }
}

Additional Note
Having OnDisable and OnDestroy being called even when the game is not playing can result into some weird unexpected behaviors

@adriengivry adriengivry added Bug Something isn't working Refactoring Something that needs a refactoring labels Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Refactoring Something that needs a refactoring
Projects
None yet
Development

No branches or pull requests

1 participant