My game is quite lagy. So I’ve started reducing lights and shadows and add a LoD. So it’s still lame I’ve started making batch groups for static things like walls and grounds. But I’ve to do more…
I change color for ground tiles at runtime, for example if go from a snowy terrain into a desert like. I change material and color of the character at runtime two. Maybe to create an opponent.
should I batch those into batch groups although?
is there any tool to visualize batch groups?
are there any best practices for the size of batch group?. default is 100, this will catch maybe 2 x 2 tiles
I first thing I notice here that is going to be taking a lot of time is:
this.entity.parent.parent.findByName();
findByName functions are one of the most expensive ways to find an asset, and having to do it every frame will really slow your app down. This is true in practically all game engines. You might want to consider creating an attribute and defining these objects in the editor, or defining them in the initialize function and using those variables/objects in update so the app doesn’t have to find the asset up to 60 times a second.
Thanx a lot I’ve seen a findByName took about 17µs to 2 ms, but there are so many, it makes total sense, that they sum up to a big total… and with bots they multiply by four…
quick search result: I use findByName() 12,830 times in 525 files , happy editing
As @eproasim mentioned, searching the scene graph is expensive, but that doesn’t mean you should not do it. There are perfectly fine times when you can do it - when the scene loads/starts, for example. You can do all the expensive stuff in the beginning of a scene start, like loading assets, searching for entities, etc. That is when you could show some loader bar, if there is a lot of stuff to load. But then you cache them and only use the cached references at run time.
findByName() and other graph node methods that help searching the scene graph for entities are not evil Don’t hesitate to use them, as they are powerful and simplify the code process. The only rule you want to follow is that you should use them only once, as mentioned and avoid using them in update methods.
I’ve tried to replace the findByName() by a static pointer.
Did this to most commonly used slow scripts (mainly the walk animotions, and for some reasons, the hide() loading screens script) about 50 scripts and 600 findByName() calls…
I get the feeling, that’s working but the values in performance test stay the same
So instead of beeing a static pointer my variable/object seems to still call findByName():
There is also an option to use findByPath. In the above script this could already be applied 3 times. I’m not sure how you can combine this the best with findByTag. I also doubt whether this is of much benefit.
Thats the first one I’ve reworked. I didn’t choose this as example because it’s less clear, but I did the same approach here, which didn’t works to well…
thats because the hierarchy tree changes on runtime. In this example “root world” is simply not loaded when the init of this script runs, and I haven’t implemented something to catch this. Every Scene like “root world” fires an event when loaded, but before I change tons of code, I want to have a solution that most likely works. I have about 50 scenes and 800 scripts, so I’ve to check before starting changing big chunks of code.
So if I can increase the FPS a litlle I’ll do things right
Right. Refactoring the code is something we all go through and is part of your growth as a programmer. Looking back at my own code I can clearly see things that could have been done better, now that I learned a little more. Later you will also meet situtations when you are going to say “Was it really me who has written this?..” Don’t give up!