When I disable a large number of game objects simultaneously via SetActive(false), this usually causes no issues at all… but if the game objects include decal projectors, we have two problems:
It burns vast amounts of CPU time to deactivate the objects.
It allocates 100s of MB of memory (GC Alloc).
Here is a test case where I’m deactivating 5000 game objects which happen to contain decal renderers… it takes nearly 1s to complete and allocates 300MB of RAM.
Does anyone know how to solve this or work around it? Why do decal projectors hate being switched off?
Couldn’t you just fully fade the projector? This way it would be invisible. Just a workaround idea. Or try to set the Component on the element ‘.enabled’ to false if it is about the number of total decals
The .enabled approach is the same - since the time spent is in the DecalProjector.OnDisable() callback (see screenshot), so the manner of disabling makes no difference.
Unless there is some known work-around or fix, indeed I will need to simply keep all decals active and rely on their fade distance. Still doesn’t sit that well with me that in a large open world, we might have 100K decal projectors sitting around when they could in theory be completely deactivated at game-object level.
I looked at the code and there is a FindIndex() in the OnDisable of the DecalProjector, the find is run on a list that contains the decal instances in the scene, so it scales quadratically with the number of decals when you disable all of them at the same time.
Additionally, a lambda is used in the FindIndex which generates GC alloc for every call of the lambda (the call number also scales quadratically).
I made the fix but it’ll take a few weeks to reach the 2022 LTS so I have attached a patch if you want to fix it locally. Note that the issue only happens in the editor so at least it shouldn’t cause any spike in a standalone player.
I’ve also noticed that the Gizmo rendering performance is fairly bad, but that’s much more complicated to fix, so I’ll keep that for later
I know this is the HDRP forum, but is there a similar issue in the setting of alpha for URP, maybe common code? Reading the patch doesn’t seem like it would be a shared cause.
I noticed in profiling that setting alpha for fading out footprints was excessive, so I only think about fading every N frames.
Hello, I have the same problem, but on URP and also in build.
I have two scenes, one of them is having around 100 decals. On the main scene I’m loading second scene with decals (async, additive). Once the scene with 100 decals will be loaded I see a pernamently huse drop of fps. In editor I can see is using 50ms on CPU. This will occur as long as the components Decals URP Projector is enabled.
But in my case this will also cause a fps drop in build.
When the decals were on main scene from the beginning (without loading them) then they don’t uses CPU this much (it was around 10ms). But I need them to be on the second scene
I’m using 2022.3.35f1, with URP. Is there anything I can do to fix this issue?