Hi all,
I searched and couldn’t find any topics about this - so I’m hoping there’s just some setting I’ve got wrong somewhere.
Unity 2022.3.14f1, WebGL
I was noticing my builds were much bigger than I expected. I have a lot in the project, but only a few things referenced in scenes. But when I look at the build report, there were textures that I can’t find being referenced in the included scenes anywhere.
So I tried a radical test: created an empty scene with just a single game object in it, removed all other scenes from build settings other than this one, closed Unity, deleted my Library folder (just in case something is cached?) and opened and built again into an empty output folder. STILL got the same huge build!
Bug? Incorrect setting?
I tried with and without compression - it just always includes everything all the time. (These textures are not in a Resources folder, btw.)
Any ideas?
Thanks!
what are the textures? my answer is if i dont want them id remove them out my asset folder into “extra junk” so i havent deleted them but i also dont have them to be built in 
Yeah, I’m all for removing things that are never used, esp since the time to import is slow. But I change which scenes are included based on what the build is for, so those are still legit assets even if they aren’t wanted for a particular build.
But even more generically, I often have a lot of test levels that I might have helper assets in there for placement, etc. Those I would never want to be in a build, but they still deserve to live in the project.
I’ve not had this issue in the past, at least on other Unity platforms (Android, iOS) - so I’m assuming that fundamentally, an asset isn’t put in the build if it isn’t referenced or in a Resources folder. Maybe that’s a wrong assumption?
1 Like
Shouldn’t be happening - not sure what is at play. We don’t have the same issue using Unity 2022.3.4f1.
At this point, do you have any custom build script that could by overriding default build settings? Might want to do another test without any scripts at all in the project.
1 Like
That’s a good point - I have a couple small scripts that have a [PostProcessBuild] attributed method. Both are simple, one copies in a javascript file to the output dir and another copies some videos into the StreamingAssets folder. I’ll try disabling them to see if they are causing issues.
How many bytes is “huge”?
How do you measure the size of the build? I suppose right-click the folder and checking the Size (on disk) property.
Could you check one specific texture that you are sure isn’t used and check that in fact it isn’t being used in any scene in the build settings scenes list and its dependencies. You can use the assetdatabase dependencies methods to recurse into resource usage.
Note that the logo texture is always included, and that texture sizes in the build report are uncompressed sizes.
Huge in this case is pretty huge:
Build Report
Uncompressed usage by category (Percentages based on user generated assets only):
Textures 1.9 gb 95.2%
Meshes 53.4 mb 2.7%
Animations 2.3 mb 0.1%
Sounds 8.8 mb 0.4%
Shaders 1.5 mb 0.1%
Other Assets 26.5 mb 1.3%
Levels 0.0 kb 0.0%
Scripts 368.1 kb 0.0%
Included DLLs 0.0 kb 0.0%
File headers 3.4 mb 0.2%
Total User Assets 1.9 gb 100.0%
Complete build size 841.2 mb
There is literally in the Editor Build Settings only 1 scene checked and that scene is absolutely empty.
This scene cannot be „empty“. Meshes, animations, sound and somehow nearly 2 gigs of textures.
Perhaps you aren‘t building the empty scene you think you are building? Or this one game object carries a reference that draws everything else into that scene. Not sure if there may be other means besides Resources that cause assets from outside a scene to be drawn into the build.
Perhaps try building a release/master build, see player settings. And build for runtime speed or size, not optimizing build time.
Hi,
I understand the skepticism, but it is a completely empty scene with 1 GameObject that has no other components added to it. The Editor Build Settings has 1 scene in it, which is this empty scene. I even named it crazy so I could be triple sure. I also deleted Library folder and made the build after a “clean” reimport.
I’m sure there’s something about this project that is causing the issue since others aren’t experiencing it, I’m just at a loss for what it could be.
I will try the release settings and set optimize for build size that you suggested next.
Thanks!
Building for optimizing size (“Disk size with LTO”) resulted in an identical Build Report in the editor log, and only a meg or so difference in the resulting Build folder.
I guess I’ll try a new project and try the same empty scene build.
So confused…
Try to use AssetDatabase.GetDependencies on the scene asset, to get its dependencies.
Or reference finder like this A reference finder for assets in a #Unity3d project. · GitHub
To see what reference individual texture
Yes - I picked a couple of textures at random and used several reference finders - they were not referenced by anything in the scene that was included in the build.
But like I said, the current test is to have a scene with a single GameObject with no other components on it - and that scene be the only referenced scene in BuildSettings… and still get just about everything included. I’m not sure what could trigger that behavior.
I’ve tried a completely clean project with some textures and built that - those are correctly not included in the build. So there’s something about my (admittedly big) project that is triggering it, I just have no idea what it could be.
There was I think a free asset on the store that allowed you to mark things as exclude from build, so irrelevant of how much something felt it needed it you could say “sod off” … However, i didnt like how it did it, which was it basically moved it out the asset folder come build time… and if they are big files (like yours) no ones got time to wait to add that to an already long enough build time…
Ive seen before a few times where erroneous unnecessary stuffs been compiled in, but its been a few k of classes or such, never have i noticed such big files - but then i guess i dont tend to have them
The reference finder listed above seems to work fairly well, although could do with a bit more feedback while it looks, so on a big project might hold it back a bit but it would be worth it
That makes sense, but something fundamental is malfunctioning. In the past, at least for other platforms in Unity, I’ve always been able to uncheck some scenes in BuildSettings and produce a build that only has some things in it. This is great for exporting a demo, or even for quick iteration testing on a real build. The fact that this doesn’t work seems like a big problem?
As is often the way with issues in production projects, it’s hard to submit a bug report for it because it requires submitting a massive amount of files (the full project) as a repro case. So I was really hoping to get some insight into how Unity decides what will be included in the build to maybe get a guess on what to investigate.
well the findreference may answer that.
As a sanity check, this build currently has only an empty scene referenced in the BuildSettings. That’s all that should be included - a single empty scene with no art (other than things like the logo that are always included). But I’m getting hundreds of megs of the other things that just happen to be in the project. Everything is being included even though only an empty scene should be in the build.
If Unity isn’t looking at the included scene files to mark things to include in the build, what does it look at?
Is there something in a Resources folder?
1 Like
There are some things in a few Resources directories spread around, but those are expected. The vast majority of the content is not in a Resources folder.
Maybe something in the resources folder reference those textures?
Any external plugin?