Unity Mobile Lag When Instantiating GameObject
Hi there, so I'm making an app with navigation of a UI menu. So I have a main menu with a button, this button loads a prefab of another GameObject with buttons and text on it that slides into view using a Coroutine.
The transition works perfectly on PC but when moving to iOS and Android devices there is lag when the object is instantiated, the lag causes the slide in effect to happen instantly. Then any recurring Instantiates, it doesn't cause the slide to happen instantly, but it isn't perfect on frame rate.
I've tried so far:
No Change: - Loading the GameObject at the start and deleting it.
Change: - Trying with SetActive(false) and SetActive(true) instead of instantiating, so the GameObject is already active in the scene. The only problem I have with this is the lag is still there, but only on the first SetActive. This is the best method I've tried as it gives me a smooth transition. Also a problem with this could be if I have a few UI objects that need loading, having them all currently in the scene at once might be an issue on performance.
I would post my code but there is a lot of it. I've attached the profiler to show the point that the instant lag happens. The other tall spike after it is me doing it again, but where the instant lag doesn't happen (just a low frame rate). So the code at this point is doing this:
Button Click
Instantiating GameObject off screen and sliding it into view using Coroutine with a lerp effect.
Once covering the screen, the GameObject with the button on it is disabled.
I know there is issues here in the profiler but I'm not quite sure how to read it, can someone help me? Thanks!