Webgl build fps decrease over time (Chrome)? - c#

We are working on optimizing our webgl build (intended to be run on chromebooks, chrome latest version).
Currently we have achieved about ~40 fps throughout the game which is quite near our requirement.
The issue is that if the game is left "on" for some time (e.g 30-45 minutes), the fps gradually drop from the initial 40 fps to about 20 fps and then continue to decrease in the same manner if game is left on.
We can say this isnt due to gpu because in all our scenes the draw calls are about 100-150 and they stay constant. Furthermore we have optimized as far as gpu is considered (static/dynamic batching, gpu instancing, disabled shadows, texture compression etc).
Currently we are unable to profile the actual build (since the development build is about 2gb which cant be loaded in any browser), hence we are profiling the editor.
Deep profiling the cpu scripts doesnt reveal anything obvious that could be gradually eating up the fps over a period of 45 minutes.
Has anyone else encountered this in their WebGl builds?
Any advice for optimization and maintaining a consistent fps?
Thanks.

Unity's audio source was causing the fps drop in the Webgl build. We replaced it with this asset and the fps drop vanished.

Related

Unity timeScale

I am creating a solar system simulator using Unity 2021.
Unity timeScale is by default 1 which translates to 1 second in real-time. There is a cap in the Editor of 100, which means that 1 second in real time equals 100 seconds in the simulation.
Now as you can imagine this cap is way too low for a "space" simulation.
Does anyone have a way or suggestion on how to circumvent this cap?
I understand how the Unity Time API works but I do not seem to find a way to achieve this.
A good example of the result desired would be the timeScale in Universe sandbox which if I am not mistaken was developed in Unity.
Thank you!
One way this can be done is the way Kerbal Space Program handles time warps up to 100,000x, which is to do the calculations for where the spacecraft should be after a specified amount of time without calculating it every in-game frame (as shown here). This method will not allow the spacecraft to be under complex physical forces such as atmospheric drag, but it can simulate accurately the predictable trajectories spacecraft go through during space travel.

Rendertexture slows down unity?

I'm confused as to what is going wrong here but I am sure that the problem is my rendertextures/video players - I have maybe 20 gameobjects that are iPhones, and I need animated .mov files that I made to play behind the screens.
To do this I followed tutorials to hook up Videoplayers with render textures (now there are about 8 of them) like this, then plugging the render texture into the emission slot in a material:
And with even 2 render textured cubes the game is INCREDIBLY laggy, here are stats
I tried turning the depth off but don't know whats wrong here - my movie files are just in the KB range. How can I play videos without lagging?
Based on the CPU taking 848ms per frame rendered, you are clearly bottlenecked on CPU. If you want to run at 30 frames per second, you'll need to get CPU time below 33ms per frame.
Since the CPU time is getting markedly worse after adding video players, it seems that the video codec is taxing your CPU heavily. Consider reducing the video quality as much as possible, especially reducing the resolution.
If that won't work, you may need to implement a shader-based solution using animated sprite sheets. That's more work for you, but it will run much more efficiently in the engine.

FPS drop after few minutes in the Android game

I have made a very simple hypercasual game everything works fine but after some few minutes of gameplay, the fps goes from 60 to 50 even the phone gets heated up. Similar to this question. I tried profiling but just can't see anything off. Tried even removing some UI elements but still no luck. Tried various vsync settings. Also, I had used this to display the fps. Even without it, the lag can be seen. Even if I just open the game and do nothing then after 5 minutes the fps will become 50. If go back using the home button and re-enter the game then the fps becomes 60 again. Using unity 2018.2.6f1. Never experienced this behavior in my other Android games.
Basically it was a faulty custom vertex shader which was applied to a plane to change the background color which changed color over time. I had not used the mobile vertex color because I was not getting the desired output. But now I'll stick to the mobile one.
The two symptoms you observed are very much likely to be connected.
The phone might heat up, as you are using its full power, which in turn makes the throttling kick in, reducing the perform
I've had the EXACTLY same problem. I was trying to fix it for a very long time. You said something about faulty shaders you use. And this is the key to solve our problem.
I use a 2-color gradient as a BG, so I have to use a shader too. Due to the fact that I'm a total noob in the writing "shader-code", I have to find something in the Internet. And it was my biggest fail)
To fix the problem and remove this fps drop you should remove your gradient and shader attached to it from the scene. And try to find a more optimized shader for 2D-game (or you can always write your own one c:)

Panorama decompression is taking too long in Unity WebGL

I have a scene with a few panoramic images.. trouble is that they each weigh a lot. On disk between 400kB ~ 1MB, on RAM load it weighs around 30MB, and after applying Texture2D.Compress() it weighs around 3MB ~ 4MB.
This scene needs to run with Unity WebGL, and for that reason it needs to take up as little memory as possible. When i run the conpression function on the image, it freezes the scene and causes very bad user experience...
I tried to find a workaround with LZMA compression but it's being too slow. Are there any other compression algorithms I can use within Unity C# environment, or any alternatives to Compress() that I'm not aware of?

Having problems with the screen resolution and screen size when Build & Running my project in Unity

When I build and run my game the graphics are very low quality. I decided to combat this by increasing my resolution, but for some reason all that did was make my application window larger upon building and running it rather than having better image quality. I am not sure where my mistake/ misunderstanding lies and would appreciate any help, as all I want to achieve is a reasonably sized window with the same graphics one gets when Maximizing on play before running one's project in unity.
I changed this by in a start method of a script writing;
Screen.SetResolution (1920, 1080, false);
I am not sure if I would also be able to do this in player settings as one is only able to change the window screen and height to the best of my knowledge...
NOTE:
I am building this for mac
HighQuality[Editor]
LowQuality[Build]
P.S. please do not vote this question down. I have only asked one question prior to this one and it originally was at 1- which got me banned for 1 day. I am therefore very unexperienced in stack overflow so if you have anything to object against my question please just leave it in the comments and I will be happy to edit my post.
There are many things that could cause the low quality rendering of your game.
First of all, select all the lights in your scene and make sure that the Resolution is set to Use Quality Settings.
Through Quality Settings:
Change the Quality to Fantastic then continue to modify it from there.
1.Go to Edit -> Project Settings -> Quality then click on Fantastic.
Build and Test. If not good, continue reading
2.The Low quality image needs more anti-aliasing.
From the Quality Settings, increase the Anti-Aliasing to about 4x or 8x Sampling.
3.Increase the Pixel Light Count.
4.You can also change the Shadow Resolution to Very High Resolution.
This is all experiment. You experiment and build each time until you find the settings that works for you. Make sure to test the frame-rate while changing these settings as they can make your game run slow.
Through Texture Import Settings:
If quality does not imporve, select your Textures(character, cube and floor...) one by one and change their Format to Truecolor.

Categories