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

Use reference counting for unity loader hook #576

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

alexqhj
Copy link
Contributor

@alexqhj alexqhj commented Feb 25, 2025

Implemented a reference-counting system for the useUnityLoader hook to track how many components are using the same Unity loader script.

  • Prevents duplicate scripts by checking if the script already exists before creating a new one.
  • Ensures proper cleanup, only removing the script when the last component referencing the script unmounts.

Why?

  • Fixes a bug where multiple hook instances are pointed to the same script and causes errors when unmounting (eg. removing a script that another instance still needs).

@alexqhj
Copy link
Contributor Author

alexqhj commented Feb 25, 2025

Sorry I didn’t open a discussion beforehand. This fix was pretty urgent for our team so I went ahead and (hopefully) patched it. There might be a better approach, but I’m hoping this at least addresses the immediate issue. Would love your thoughts.

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