- Home /
reduce memory usage
hi, I'm developing my first work in unity3d the problem is that memory usage is too high (over 3gb)
any suggestion to reduce memory please? thanks in advance bye
Before my Firefox died i saw many cars, how many polys has one car? And i saw many informations, is memory usage keeps growing during game?
memory usage grows only during game loading I make many operations on texture combining, resizing, rotating them I've seen that without doing it (I need it to paint cars) memory usage goes from 3,3 gb to 1,8 gb Is there a way to deallocate memory after I've made operations on textures? thanks
How many Poligons (triangles) has one car model and how many of them is on track?
You need to make low-detail models. You should be ai$$anonymous$$g for <3000 polys for NPC cars, and <10000 for the player's car. Basically, in just one of those cars you have almost more than you should have on all the cars combined!
Answer by trumanita · Nov 16, 2011 at 10:40 AM
I think I've solved I share it for those could have the same problem During loading of resources I call
Resources.UnloadUnusedAssets
Now ram usage is at 0,7 gb !!!
Answer by ChrisSpears · Nov 14, 2011 at 09:41 PM
High polygon counts use some memory but not GBs! We obviously don't have enough information to diagnose this issue but my money is on high-res (4K x 4K maybe?) textures that they are making unique for the cars. Make a copy to paint the number of the car. Do that for 20 cars with a spec and a bump and you've got:
4096x4096x4 bytes (32 bit RGBA)x 3 (spec, bump, diffuse) x 20 cars = almost 4GB
If that is the case, either apply the number as a separate texture, use smaller textures, or only paint the number in a smaller portion of the model so it is just a small chunk of the car.
Again, without more information we are all just throwing darts so any more information would be super helpful.
Answer by TheGamedevGuru · Sep 25, 2019 at 07:32 PM
Give Unity Addressables a try. It'll help you with asset lazy loading, while still keeping the references workflow. Plus, it's really easy to upgrade. I wrote an extensive tutorial on Unity Addressables: https://thegamedev.guru/unity-addressables-learn-workflows/
Please don't answer questions without activity since 2011, these questions are outdated in many ways?
A question on how to optimize memory usage will never be outdated. Plus, it is one of the top results in google when looking for this problem.
Answer by trumanita · Nov 14, 2011 at 10:02 PM
first of all, thanks to everybody my textures aren't so large (max is 1024x1024, but I usually use 512x512) I paint cars dynamically depending on data loaded and I make many operations on textures (I suppose this is the problem, because using models as loaded without painting them, memory usage goes from 3,3 gb to 1,8 gb I use code like this:
public static Texture2D CombineTextures2 (Texture2D aBaseTexture, Texture2D aToCopyTexture)
{
int aWidth = aBaseTexture.width;
int aHeight = aBaseTexture.height;
int cWidth = aToCopyTexture.width;
int cHeight = aToCopyTexture.height;
Texture2D aReturnTexture = new Texture2D (aWidth, aHeight, TextureFormat.ARGB32, false);
Color[] aBaseTexturePixels = aBaseTexture.GetPixels ();
Color[] aCopyTexturePixels = aToCopyTexture.GetPixels ();
Color[] aColorList = new Color[aBaseTexturePixels.Length];
int aPixelLength = aBaseTexturePixels.Length;
int row = 0, column = 0;
for (int p = 0; p < aPixelLength; p++) {
row = p / aWidth;
column = p - row * aWidth;
//if(row==242)Debug.Log(aToCopyTexture.GetPixel (column , row));
//aColorList[p] = Color.Lerp(aBaseTexturePixels[p], aCopyTexturePixels[p], aCopyTexturePixels[p].a);
if (aToCopyTexture.GetPixel (column , row).a >0 ) {
aColorList[p] = aToCopyTexture.GetPixel (column , row);
//if(row==242)Debug.Log("sost");
} else
aColorList[p] = aBaseTexturePixels[p];
}
aReturnTexture.SetPixels (aColorList);
aReturnTexture.Apply (false);
return aReturnTexture;
}
Answer by trumanita · Nov 15, 2011 at 11:38 AM
I've found a partial workaround: in my CombineTextures method now I do:
aReturnTexture.Compress(false); aReturnTexture.Apply (false,false);
I've reduced memory usage from 3,5 gb to 2 gb (still not completely satisfied) Any suggestion is still welcome Thanks