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

Unload scene specific resources on demand #7381

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ViktorVovk
Copy link

This is an implementation of functionality for unloading all resources from the scene we are leaving. For example, we have several scenes (Preloader, postPreloader) that contain a significant number of resources such as images, audio, spine animations, atlases, JSON files, and so on. After these scenes have been loaded, once we transition to the so-called main scene, we want to remove (unload) all resources from the scenes that we do not expect to return to during the game’s runtime.

Plan for implementing the unloading of scene-specific resources on the GDevelop side:

  1. An additional boolean parameter needs to be added to the "change scene" action. Enabling this parameter will indicate that all resources specific to the scene being exited should be unloaded. It is assumed that we will not return to this scene during the game’s runtime.

  2. During the execution of the "change scene" action, the _destroy method is eventually called on the scene object (in runtimescene.ts). At that point, the resource cleanup method disposeScene—implemented in the ResourceLoader class—is invoked.

  3. The disposeScene method accepts the scene name as a parameter and creates a Map where the keys are resource types (ResourceKind) and the values are arrays of ResourceData.

  4. In the ResourceLoader class, there is a field _resourceManagersMap where the keys are resource types (ResourceKind) and the values are resource managers. This makes it easy to correlate this map with the map of resources grouped by type since they share the same keys.

  5. In each resource manager class, a method disposeByResourcesList has been implemented, which takes an array of resources that need to be cleared. This method performs the cleanup of the resources in the provided list.

@ViktorVovk ViktorVovk marked this pull request as ready for review February 7, 2025 16:50
@ViktorVovk ViktorVovk requested a review from 4ian as a code owner February 7, 2025 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant