51
votes
Accepted
Blank 2.2 KB sized PNG costs 2.1 MB in Unity? What does this represent? What to do?
PNG compression works by predicting the next pixel from the pixels that came before.
If the image is completely blank, ie. every pixel is exactly the same as the pixel that came before, then that ...
40
votes
Accepted
Why should I always consider creating and using object pools instead of instantiating the new object on the fly?
If you're planning to instantiate many instances of the same prefab, you should definitely think about using object pooling. Calling Unity's Instantiate function is one of the most taxing method calls ...
28
votes
Difference in glDrawArrays and glDrawElements
Each glDraw* is a draw call.
1 glDrawArrays is 1 draw call.
1 glDrawElements is 1 draw call.
It doesn't matter (so far as draw call count is concerned) how many vertices or indices you use, 1 glDraw*...
27
votes
Accepted
Is A* efficient even when the obstacles are moving?
There are multiple algorithms that are much faster than A* when you need to recalculate a path with moving obstacles. See here under "Simple Recalculations".
However, you're not likely going to find ...
15
votes
Accepted
Use floats or doubles when writing mobile games
You'd be hard pressed to find a mobile GPU that could use doubles even if you wanted to, so that part of the choice is pretty much made for you.
There are only a few places where you might benefit ...
12
votes
Accepted
Unity3d - Do I need to destroy gameobject AND script?
You only need to destroy the GameObject.
By destroying the GameObject (Destroy(this.gameObject);), you also destroy the script (...
10
votes
Is A* efficient even when the obstacles are moving?
Yes. A* is still the way to go in almost every case. It's your node cost calculation that becomes dynamic and therefore more complex to calculate and track.
If you already know where the moving ...
5
votes
Accepted
Issue with Texture2D memory leak in Unity
Assets in Unity (textures, materials, etc) are not garbage collected as readily as other types. Unity will clean up unused assets on scene loads, but to keep this cruft from piling up it's our ...
5
votes
Accepted
How does Godot 4 copy vectors?
Checking the GDScript reference docs:
Built-in types
Built-in types are stack-allocated. They are passed as values. This means a copy is created on each assignment or when passing them as arguments ...
4
votes
Accepted
Is single/double frame allocator suitable only for POD datas?
You have 2 options,
keep track of destructors that need to be called and call them on clear
Make sure that any object stored in the stack will only allocate from a allocator that will be cleared ...
4
votes
Accepted
Efficient Dynamic Memory Management
deleteBuffer will delete the buffer in WebGL (and OpenGL) but I'm just curious, is there any reason not to just reuse the same buffer just put new data in it? (eg. have a pool of buffers?)
4
votes
Unreasonably large memory use with high-res screenshot script
Textures, RenderTextures, and Materials use memory outside of C#'s managed heap (including ...
4
votes
Accepted
How do open world game engines allocate memory?
Creating a seamless open world without loading bars is not an easy task. There are lots of small and large problems which need to be solved. This is not a beginners project!
The basic approach is ...
4
votes
Accepted
Game Engine Memory Allocator
What kind, and how many, allocators you need depends on what you're doing with memory. If you want a particle system, then you should probably create a pool allocator, as it's often the most efficient ...
4
votes
Accepted
I am testing the flyweight pattern on thousands of GameObjects but its not helping save memory. What am I doing wrong here?
When it comes to components referencing assets, then the engine is already using the "flyweight" pattern internally. When multiple SpriteRenderers render the same sprite asset, then they are ...
3
votes
Any advantage of having chunks with sizes by the power of two?
The main advantage of power-of-two sizes is that division by a power of 2 (on an integer) is just a bit shift, and modding is just a mask. Both of these operations are blazingly fast to do on gobs of ...
3
votes
Libgdx game crashes on some devices without any Errors / Logs
As I can see, you probably think that if your image takes 30kb on disk it will allocate 30kb of RAM - it won't!
Classic 32 bit PNG file (with transparency) has 4 values - R (255 combinations), G (...
3
votes
Accepted
Should I avoid constructors/destructors in C++ when using custom allocators?
New and delete are only an issue when used excessively (10,000+ times per frame).
This usually means an engine architectural redesign is in order. Allocation pools rarely fix this.
But if you must:
...
3
votes
Static variable pre-declaration & memory heap expansion in Unity
Local variables are not added to the heap. They are pushed onto the stack and immediately popped off the stack when they leave scope, thus already avoiding the heap (and the sort of memory allocation ...
3
votes
Accepted
How can I make a custom memory allocation for classes with virtual methods?
Take a look at std::allocator_traits that will allow you to use your allocator and construct objects in allocated space.
If you don't want to use that you can use placement new: ...
2
votes
Accepted
Best way to add and remove quads in a VBO?
You don't need a dictionary for this, just use an infinite array (c++ - vector, java - arraylist, c# - list) and store an id in the order they can be found in the vbo. If you want to remove one of ...
2
votes
Accepted
How do open world games handle efficiently enemy respawn?
When you need to persist the state of a chunk but you are running out of memory, consider persisting it to the hard drive. If your game has enough complexity and data to warrant it, you might want to ...
2
votes
Memory is not getting freed on Destroy()
1000 isn't enough. I have taken your scripts and modified them a bit and it's showing that everything is working correctly. Instantiating 1000 objects gives you less than 1 mb - if you have seen any ...
2
votes
2
votes
Accepted
If I create a prefab out of an object on scene will my game take more memory in Unity?
.PREFAB files are just text files taking very little space. Prefabs are just saved information of how the game object should be configured or what components should be attached at the time of ...
2
votes
If I create a prefab out of an object on scene will my game take more memory in Unity?
It depends on how you use them, but generally prefabs will take memory in the game (not just in the editor), even if you do not instantiate them.
More concretely, any prefab that is referenced by a ...
2
votes
How does Godot 4 copy vectors?
Vectors in Godot are value types, not reference types. Furthermore, they are not considered objects.
But since "object" might mean slightly different things depending on context, I'll be ...
1
vote
Quickly Running Out Of Memory
Generic advices.
Don't use png. It's good for intermediate image processing, acceptable in some test runs, but it's quite slow for loading and needs extra ram for decompressing.
Use the texture file ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
memory-efficiency × 154memory × 27
unity × 26
c++ × 23
optimization × 23
opengl × 16
java × 13
2d × 13
libgdx × 11
architecture × 10
textures × 9
c# × 8
tilemap × 7
design-patterns × 7
android × 6
sprites × 6
ios × 6
tiles × 6
opengl-es × 5
javascript × 4
algorithm × 4
graphics × 4
directx11 × 4
data-structure × 4
gameobject × 4