unity-rlottie icon indicating copy to clipboard operation
unity-rlottie copied to clipboard

Switch out lottie files at runtime

Open gardyna opened this issue 2 years ago • 4 comments

I have a situation where I have to choose between several lottie files at runtime to display. I don't think having several gameobjects in the scene and selecting between those is elegant. Would it be possible to add a "SetLottie" function to the AnimatedImage object?

gardyna avatar Oct 16 '23 10:10 gardyna

Hello @gardyna, thanks a lot for the suggestion! Sorry for the long reply, I was busy on other projects. I will implement the API for this feature in the next versions.

gindemit avatar Dec 31 '23 14:12 gindemit

I have a situation where I have to choose between several lottie files at runtime to display. I don't think having several gameobjects in the scene and selecting between those is elegant. Would it be possible to add a "SetLottie" function to the AnimatedImage object?

This would be very useful.

JonFaull avatar Mar 19 '24 16:03 JonFaull

Hey @gardyna and @JonFaull I just reviewed again the existing implementation. The AnimatedImage monobeh does has a public method LoadFromAnimationJson() You can use it on the same AnimatedImage instance to load new animations. It will automatically unload the already loaded animation. No need to dispose it explicitly. You need to provide at least 3 parameters: string json, uint width, uint height

You can see an example how to use this method on the dev branch in the repo_root/unity/RLottieUnity/Assets/LottiePlugin/Tests/Runtime/src/AnimatedImageTests.cs file

gindemit avatar Mar 21 '24 21:03 gindemit

Hi @gindemit The code in AnimatedImageTests.cs looks like exactly what I need. I am having issues fetching it for my project to try out. Any estimation on when it will be released?

gardyna avatar Mar 25 '25 10:03 gardyna