mob-sakai / UIEffect

UIEffect is an effect component for uGUI element in Unity. Let's decorate your UI with effects!
https://github.com/mob-sakai/UIEffect
MIT License
5.63k stars 774 forks source link

Material caching is not working properly #163

Closed kwasak closed 5 years ago

kwasak commented 5 years ago

UIEffectBase.OnValidate() is increasing the amount of time it takes to enter playmode. In my project, UIEffectBase.OnValidate is adding an extra 2s.

Screen Shot 2019-04-09 at 10 01 03 PM

mob-sakai commented 5 years ago

Hi @kwasak Thank you for reporting.

I would like to know more information on this issue. Unity version, platform, more profiler infomation...

kwasak commented 5 years ago

You’re welcome! Unity 2018.3, iOS.

For the profiler information, the attached screenshot is all I got for profiler information.

On Apr 9, 2019, at 10:48 PM, Takashi Sakai notifications@github.com<mailto:notifications@github.com> wrote:

Hi @kwasakhttps://github.com/kwasak Thank you for reporting.

I would like to know more information on this issue. Unity version, platform, more profiler infomation...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/mob-sakai/UIEffect/issues/163#issuecomment-481512551, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ABqdSu4RW8dXMiIxpW_vus9buazRPW7dks5vfVETgaJpZM4cl9av.

mob-sakai commented 5 years ago

Thank you, @kwasak ! Can you submit a reproducible project for this issue? It helps me to resolve the issue.

kwasak commented 5 years ago

Sorry, this took so long. I'm on a tight schedule with a project I'm working on. It appears the issue stems from a call to MaterialResolver.GetOrGenerateMaterialVariant()from UIShiny.

MaterialResolver.GetOrGenerateMaterialVariant()calls GetMaterial() which makes an expensive call to AssetDatabase.FindAsset(). This call occurs for every UIShiny object in the scene.

As you can see from the attached image, in my case, this adds 3.7s to Assembly Reload Time. AsGetOrGenerateMaterialVariant() is called from OnValidate().

From what I see, the solution would be cache the material received from GetMaterial().

Screen Shot 2019-05-24 at 1 20 50 PM

UISmartShiny is a class I inherited from UIShiny, for the purpose of this bug their identical, this occurs in both my version and the original UIShiny.

I hope this helps, I apologize again for the late reply.

mob-sakai commented 5 years ago

@kwasak Oh, sorry. I missed this issue. I will fix it soon.

mob-sakai commented 5 years ago

WIP image

GC: 41.4MB -> 232.5KB

Try it. MaterialResolver.cs.zip

kwasak commented 5 years ago

Awesome, great improvement. 41MB to 232KB is amazing!

On May 24, 2019, at 8:33 PM, Takashi Sakai notifications@github.com<mailto:notifications@github.com> wrote:

WIP [image]https://user-images.githubusercontent.com/12690315/58362249-1c9f2580-7ed0-11e9-97c0-2961cb142478.png

GC: 41.4MB -> 232.5KB

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/mob-sakai/UIEffect/issues/163?email_source=notifications&email_token=AANJ2SWEFG2KJFKBY3GIAKTPXCCPDA5CNFSM4HEX22X2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWGZY2A#issuecomment-495819880, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AANJ2SSNS7SYWEKR63DVGALPXCCPDANCNFSM4HEX22XQ.

mob-sakai commented 5 years ago

The cause of the problem is that the material cache was not working properly. If there is no problem, it will be released. Try it on your project. :)