Need API for Manual Initialization of PrimeTweenManager #157
Replies: 3 comments 4 replies
-
Hey @JohnBaracuda, thank you for the great suggestion!
The thing is, I never designed PrimeTweenManager to be null at runtime, hence the error wording that mentions Edit mode. Also, doing lazy initialization on the first call will lead to huge initialization spikes, so I create PrimeTweenManager and allocate all the necessary memory at the earliest possible moment. |
Beta Was this translation helpful? Give feedback.
-
@JohnBaracuda I added an experimental To enable experimental features, please add the PRIME_TWEEN_EXPERIMENTAL define to the 'Project Settings / Player / Other Settings / Scripting Define Symbols'. |
Beta Was this translation helpful? Give feedback.
-
Hi @KyryloKuzyk, this works, thank you! I noticed one small thing: PrimeTweenConfig.ManualInitialize() throws an error if PrimeTweenManager.HasInstance is true. It works fine for me right now, but since I am not sure if the order of RuntimeInitializeLoadType.BeforeSceneLoad callbacks is guaranteed, I'm slightly worried this might randomly break later if the execution order changes. Would it make sense to either remove that error check (since calling it after initialization seems harmless), or expose HasInstance publicly so we can check if initialization is needed first? Alternatively the method could just return a bool to indicate whether initialization happened. Either way, really appreciate you adding this :) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I am porting my game from DOTween to PrimeTween and encountered an initialization issue. My game uses a custom installer system that runs during
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
. This ensures all global settings and managers are set up before any Awake() methods are called, allowing me to basically start from any scene without without any issues.However, PrimeTweenManager also initializes during
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
which causes a problem because it always runs after my installer. As a result, any UI isntances with Tweens that I spawn or calls to PrimeTweenConfig trigger the error:"Please don't call PrimeTween's API in Edit mode"
To work around this, I manually invoke the beforeSceneLoad() method from my installation method via reflection:
This solution is obviously fragile and will break anyway in builds because the Assert in PrimeTweenManager.beforeSceneLoad() will be stripped, leading to duplicate managers.
So here is my suggestion to fix this:
• Expose an API to manually initialize the PrimeTweenManager.
• Add a public Initialize() method that can be called early.
• Use a static _isInitialized flag to prevent duplicate initialization.
• Reset _isInitialized during [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] to ensure proper domain reload behavior.
Or you can add lazy initialization, which initializes the entire system as soon as the instance is accessed. In the editor, you can use Application.isPlaying to check if the play mode or edit mode is currently active. The message "Please don't call PrimeTween's API in Edit mode" is incorrect because it isn't actually checking if we are in edit mode; rather, it's checking if the Instance of the PrimeTweenManager is null.
This would allow users to control initialization order while maintaining the existing automatic setup as a fallback.
Beta Was this translation helpful? Give feedback.
All reactions