Hi guys, Im trying to implement a system to enable/disable rendering, changing the renderingFilter.ShadowCastingMode to ShadowCastingMode.On and ShadowCastingMode.ShadowsOnly.
For this Im using a tag system to call the exchange, called NotVisibleTag.
But using the AddComponent and RemoveComponent functions it seems to get more and more memory allocation.
I wanted to see if there is any alternative to avoid this.
#Questions about ECS memory allocation
1 messages · Page 1 of 1 (latest)
IEnablableComponents
Thanks @safe bronze!
Hi, another question!
Seems like when accessing DynamicBuffer<Child> generates memory allocation, there's right?
Entities.
WithBurst().
ForEach((Entity entity, int entityInQueryIndex, in DynamicBuffer<Child> children)
{
foreach (var child in children) // here generates memory allocation
}```
If rights, in what ways I can circumvent this and iterate?
no it doesn't
but iterating over buffer is indeed not super fast, so if collection is big - you can foreach over children.AsNativeArray()
so... I think the parallelEcb generates instead:
var nativeChildren = children.ToNativeArray(Allocator.Temp);
int i = 0;
foreach (var child in nativeChildren)
{
parallelEcb.SetComponentEnabled<ObjectVisibleComponentData>(i, child.Value, isVisible);
parallelEcb.SetComponentEnabled<ChangeRenderTag>(i, child.Value, true);
i++;
}
nativeChildren.Dispose();
not like this
As
not To
sorry, change to AsNativeArray
var nativeChildren = children.AsNativeArray();
confirming, using parallelEcb.SetComponentEnabled or ecb in child makes memory allocation
removing these lines its not generate memory allocation
ofc it does
it's command buffer
and you are writing commands
ok, but I finally figured it out...
SetCollisionFilter generates a huge memory allocation.
this called for another system but triggered on that ChangeRenderTag.
I use this to deactivate some collisions detection
RenderSystem.cs
foreach (var (changeRenderTag entity) in
SystemAPI.Query<RefRO<ChangeRenderTag>>().WithEntityAccess())
{
RenderFilterSettings renderFilterSettings = state.EntityManager.GetSharedComponent<RenderFilterSettings>(entity);
bool hasVisibility = state.EntityManager.IsComponentEnabled<ObjectVisibleComponentData>(entity);
var collider = state.EntityManager.GetComponentData<PhysicsCollider>(entity);
// Starts here
if (!hasVisibility)
{
collider.Value.Value.SetCollisionFilter(_notVisibleCollisionFilter);
}
else
{
var baseColor = state.EntityManager.GetComponentData<URPMaterialPropertyBaseColor>(entity);
collider.Value.Value.SetCollisionFilter(baseColor.Value.w >= 1f ? _visibleCollisionFilter : _alphaVisibleCollisionFilter);
}
// Ends here
renderFilterSettings.ShadowCastingMode = hasVisibility ? ShadowCastingMode.On : ShadowCastingMode.ShadowsOnly;
ecb.SetSharedComponent(entity, renderFilterSettings);
ecb.SetComponentEnabled<ChangeRenderTag>(entity, false);
}
theres another way to change the filter without generating memory allocation or cleaning after changing it?
or other way to deactivate and reactive collision? Disabled tag maybe?
well, when I use the app for a seconds, hes increasing 300 MB of memory to the Android phone
when I comment the SetCollisionFitler lines, its works normally
this huge memory allocation its causing a crash for OutOfMemory
🤔
yes this is giving me a headache
Ya u can try Disabled tag. Any reason why u didn't use it?
I doubt it's related directly
since those commands
are not even allocating anything
they just write values to existing memory
and for sure they won't be allocating 300mb
Not really sure but looks like this API keep allocating new memory each time u call it. I suggest u to submit bug report
because I need to use it for some interactions
but I can test for sure
yes, I can create a project test, only for test this
Disabled tag works without any memory allocation, I will investigate if this is a bug or not (SetCollisionFilter)
Thanks @safe bronze and @silk gorge for your time
I guess since physics using blob asset, maybe tat API keep creating new blob asset each time u call it.