1)ParticleSystem Your memory will be affected MaxParticles Influence
2) Use the code to modify the image compression format and report an error
3)Unity Texture import settings have an impact on memory
4)Unity Solution for video playback in
This is the first 285 piece UWA Push of technical knowledge sharing . Today we continue to select and develop a number of 、 Optimization related issues , Suggested reading time 10 minute , If you read it carefully, you will get something .
UWA Question answering community :answer.uwa4d.com
UWA QQ Group 2:793972859( The original group is full )
Memory
Q:ParticleSystem Your memory will be affected MaxParticles Does the value set affect ?
A: Did a test on the real machine ,Unity 2020.3.17, millet 9. The special effect of the test is Unity default ParticleSystem Special effects , give the result as follows :
As you can see from the picture above , Memory is affected by “ The actual maximum number of particles ” Influence ,( It can be roughly understood as duration * Number of launches per second , Don't consider Burst How to launch ). When the number of launches is 0 when ,ParticleSystem There is a 9416Byte Memory footprint , This is Unity Occupation of built-in serialized things .
in addition , When “ The actual maximum number of particles ” after ,Active The number of particles increases with playing time , Memory usage will not change , As shown in the figure below .
PS:
When ParticleSystem What was launched was Mesh when , Can cause Gfx Memory up , And this Mesh Memory usage is not counted Assets/Mesh In memory usage .
thank [email protected] The Q & a community provides answers
Texture
Q: When you want to add a picture , Automatic processing of picture settings , As a result, the setting of the picture times is wrong , There is no solution on the Internet , Error is as follows :Selected texture format ‘Unsupported’ for platform ‘Android’ is not valid with the current texture type ‘Sprite’.
Unity edition :2019.4.34f1
public class TextureImporterProcessor : AssetPostprocessor
{
void OnPostprocessTexture(Texture2D texture)
{
bool haveAlpha = textureImporter.DoesSourceTextureHaveAlpha();
textureImporter.isReadable = false;
textureImporter.mipmapEnabled = false;
textureImporter.alphaIsTransparency = haveAlpha;
textureImporter.textureType = TextureImporterType.Sprite;
textureImporter.textureCompression = TextureImporterCompression.Compressed;
TextureImporterPlatformSettings androidSettings = new TextureImporterPlatformSettings()
{
name = "Android",
overridden = true,
format = haveAlpha ? TextureImporterFormat.ASTC_RGBA_6x6 : TextureImporterFormat.ASTC_RGB_6x6,
};
textureImporter.SetPlatformTextureSettings(androidSettings);
TextureImporterPlatformSettings iOSSetting = new TextureImporterPlatformSettings()
{
name = "iPhone",
overridden = true,
format = haveAlpha ? TextureImporterFormat.ASTC_RGBA_6x6 : TextureImporterFormat.ASTC_RGB_6x6,
};
textureImporter.SetPlatformTextureSettings(iOSSetting);
textureImporter.SaveAndReimport();
}
}
A1: It may be the problem of texture format , I'll put ASTC_RGBA_6x6 Change to ASTC_6x6 There is no such error report .
Thank you Zong Huixuan @UWA The Q & a community provides answers
A2: Add upstairs ,TextureImporterFormat There is a problem with the format specification ,ASTC Integrated with A The format of , So the code is unified into ASTC_x 了 . In the new 2020 There is no more in the version ASTC_RGBA And ASTC_RGB The distinction between , All unified into one interface ASTC_x In the , It should be the problem of version transition ,Unity 2019 There are many transition problems , stay 2020 It's much better up there .
Thanks to Liao Wuxing @UWA The Q & a community provides answers
Texture
Q: a sheet 2048x2048 But the actual pixels are only 512x512, And a 512x512 What's the difference between your pictures ? We're making a system like a paper doll , Want to set a standard . Currently scheduled 512x512 The size of the ( For scalability ). But most dress up sizes may actually be only 250x250, Want to know if there is actually a difference between loading and memory ?
A1: Experimental data , The size of the same picture is 1024 Graph , The project settings are as follows , Compare the results :
The above test data are in PC Test data under . Data on the phone , The landlord can test it by himself . In the early stage, we can consider using 512 Make the original drawing according to the size of , Then make a tool , Select the compression size you need when sending out the package .
Thanks to Liao Wuxing @UWA The Q & a community provides answers
A2: Continue to answer upstairs .
After the texture is loaded into memory, the calculation formula of memory occupation is :
Texture memory ( byte ) = wide x high x Pixel byte
Pixel byte = Number of pixel channels (R/G/B/A) x Channel size
in other words : Runtime size = Long x wide x The size of each pixelgive an example :RGBA 8888 It represents the channel RGBA Each channel occupies 8bit So one pixel takes up 4bytes. so , If the picture size is 1024x1024, Then size =1024x1024x4/1024/1024 = 4MB.
In the example upstairs ASTC 4x4 block Compressed format .
ASTC 4x4 block Compressed format , Each pixel occupies 1 byte ,8bits. a sheet 1024x1024 The compressed size of the map is 1MB.
Thank you, Ma San @UWA The Q & a community provides answers
Video
Q: Need to play video in the game , Meet some basic needs , For example, play remote video , Broadcast as you go down , Set the video playback speed , Video progress bar , Pause or something .
Currently known, you can use your own Video Player、AVPro and Sofdec2 These three paragraphs , I'd like to ask if there is any big guy system that has studied video playback , Can share a little experience , Thank you for .
A: On the three video methods mentioned in the title , I used Video Player and AVPro.
In ordinary use Video Player Has been able to meet most of the needs , But in terms of video compatibility , And platform applicability ,AVPro than Video Player Much better , and Video Player You also need to encapsulate some interfaces to facilitate your use .
Video Player There are some specific required formats on each platform , Therefore, we should also control our own compatibility , And probably in Android On the platform , Some videos will cause some inexplicable black screens . Its advantage lies in its lightness , No need for too much Integration , Good compatibility with the engine , Upgrading the engine will not cause the trouble of inconsistent versions .
AVPro Some of the disadvantages of are more functions , For some unnecessary functions , Will be more bloated , It's not as compatible with the engine Video Player. The advantages are obvious , The function is still very powerful , And it has a good performance in the compatibility of the platform . There are some fixed decoding algorithms , stay Android The performance on the platform is the most obvious .
Many things are double-edged . Look at your needs , No best , Only the most suitable . If you have something, you must give it up , Give and take . You should be specific to your needs and the limitations of the current project , Think about what suits you .
Thanks to Liao Wuxing @UWA The Q & a community provides answers
The cover image comes from :GPU Particles Unity
be used for Unity Of GPU particle system .
Today's sharing is here . Of course , There is no end to life but to know . In the long development cycle , The problems you see may be just the tip of the iceberg , We are already in UWA The Q & a website has more technical topics waiting for you to explore and share together . You are welcome to join us , Maybe your method can solve other people's urgent needs ; And he's a mountain “ stone ”, Can also attack you “ jade ”.
Official website :www.uwa4d.com
Official technology blog :blog.uwa4d.com
Official Q & a community :answer.uwa4d.com
UWA School :edu.uwa4d.com
Official technology QQ Group :793972859( The original group is full )