Hello everyone ,
I recently got the draw call minimizer by purdyjo and It perfectly worked with the sample project .
The problem is , my game generates buildings and road while in game so I can’t parent all my object to a single object because the script should be put under a parent object that contains all game objects to optimize it.
Is there any way I could do this ?
Please help :sad:
GameObject newObject = new GameObject("Test");
newObject.transform.parent = DrawCallScript.Instance.CachedTransform;
(this assumes you have a singleton called DrawCallScript that contains the script, obviously this is not necessary)
btw : my game is based on this kit : Unity Asset Store - The Best Assets for Game Making
I dont want to post my edited game but the script for spawning objects are the same as this .
If anyone has this kit or knows how it works please give a piece of advice to me
I’m not that familiar with either of those assets, but I don’t think that what you’re trying to do will actually work. DrawCallMinimizer works by taking all the meshes and textures in its children and combining them in edit-mode so that you get faster speed while in play-mode. If you try to make it constantly rebuild the meshes and textures with a bunch of changing meshes and textures while your game is actually running, it’s probably going to be slower than the extra draw call would be. You’ll get a frame rate “hiccup” every time it has to rebuild the combined meshes. The best thing you could do would be to use DrawCallMinimizer on your prefabs and things while in edit mode so that they all use the same texture atlas and material, and then let InfiniteRunner draw them like it normally does. Drawing a bunch of meshes that are using the same material and texture is generally almost as fast as drawing one big combined mesh; in some cases it will actually be faster.
First of all, it’s very unlikely an infinite runner will generate enough draw calls to begin with if it’s programmed well. Secondly, how many draw calls do you have? it might not be the problem. If its 20-30 draw calls then it most likely isn’t the problem.
Now garbage collection will trip up a noob every single time. Especially if you’re modifying strings or working with them every frame… like score or such. That will cause some badass hiccups.
You need to go pretty low end but 70 draw calls would be choppy for a very cheap device, and even then it depends on how much cpu is being used by your scripts. So 70 can be smooth if your scripts aren’t doing much
Why not get a low end device to test? probably they’d be slowed down by the graphics first.
Yeah half that would be ideal…can you shorten the camera frustum without impacting visuals? Also culling by layers and distance could help. So you draw some objects way far out, and the smaller items only when they’re closer to the player. Takes some playing with but you can have several distances that things are rendered and still have it look good.
If it is 2D, like canabalt, all you need is to destroy buildings that player passed through and which are outside camera’s view. If it is 3D runner game (like flash game Run), you want to delete all stuf that is behind camera.
If possible, it is much better for performance to never create/delete game objects during gamplay. You should always pool objects where possible and only hide/show when needed or you’re likely to see pauses all over the place.
Yes, pooling is good as well, but there are few shortcomings such as disappearing objects (when pool is too small and objects that are still visible gets reused). For that I can recommend thing what I call dynamic pooling.
The base for pool is following struct:
struct PoolObject{Object go;
bool active}
“active” means that object is in use and shouldn’t be reused.
Actual pool (of PoolObject) starts empty (I won’t be forcing specific data structure on you here as it largely depends on your coding style). Then if all objects have “active” set to true or there is no objects in the pool, you create new PoolObject and add it to pool, then use it. In other case, you reuse first “PoolObject” with “active” set to false. If you don’t need specific object anymore, you lookup it in the pool and set “active” bit to false.
I’ve read that StringBuilder and String.Format also have allocation and performance problems.
My initial guess is to pool single character text meshes or character sprites for each character position that can potentially change. Or as mentioned earlier in another thread, to use a co-routine to update text.