Skip to main content
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 ...
DMGregory's user avatar
  • 135k
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 ...
Kevin H.'s user avatar
  • 498
27 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*...
Maximus Minimus's user avatar
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 ...
BlueRaja - Danny Pflughoeft's user avatar
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 ...
DMGregory's user avatar
  • 135k
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 (...
Evorlor's user avatar
  • 5,803
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 ...
Stephane Hockenhull's user avatar
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 ...
DMGregory's user avatar
  • 135k
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 ...
DMGregory's user avatar
  • 135k
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?)
gman's user avatar
  • 840
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 ...
ratchet freak's user avatar
4 votes

Unreasonably large memory use with high-res screenshot script

Textures, RenderTextures, and Materials use memory outside of C#'s managed heap (including ...
DMGregory's user avatar
  • 135k
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 ...
Philipp's user avatar
  • 120k
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 ...
Ted Klein Bergman's user avatar
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 ...
DMGregory's user avatar
  • 135k
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 ...
Ed Marty's user avatar
  • 5,229
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: ...
ratchet freak's user avatar
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: ...
Stephane Hockenhull's user avatar
3 votes
Accepted

CPU and RAM usage in OpenGL too high in Swift

The first issue is that you are re-creating and destroying the buffers, reloading the texture, and recompiling the shader on every single draw loop. This is the source of the huge CPU usage. As for ...
Stephane Hockenhull's user avatar
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 (...
Jacob's user avatar
  • 2,552
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 ...
Bálint's user avatar
  • 14.9k
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 ...
Philipp's user avatar
  • 120k
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 ...
Candid Moon _Max_'s user avatar
2 votes

Unreasonably large memory use with high-res screenshot script

I finally used this code : ...
Maifee Ul Asad's user avatar
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 ...
Ravi Prakash's user avatar
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 ...
Jorge Galvão's user avatar
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 ...
Theraot's user avatar
  • 27.2k

Only top scored, non community-wiki answers of a minimum length are eligible