I am working with Unity ECS and am having trouble with DynamicBuffer
. I get a reference to one using SystemAPI.GetBuffer
. I can validate in the inspector that the buffer has elements, but when I get it using the query it is empty.
My hope with this post is to get some common situations in which a DynamicBuffer
can be unexpectedly empty. Please post below. Hopefully the collected information will help me and potentially someone else also.
Here is a condensed snipped of my system.
foreach (var link in SystemAPI.Query<OtherEntityLink>())
{
var linkedEntity = link.Entity;
var buff = SystemAPI.GetBuffer<SomeBuffer>(linkedEntity);
// buff.Length == 0
// A foreach on the buffer has 0 iterations
}
I can of course post more code but I thought I would start with just a basic description. Here is some more context information.
linkedEntity
is the correct entity which has the populated buffer on it. I have verified this through the inspector.- Initially I thought the issue might be that
linkedEntity
also has theDisabled
component. But after testing without that component the buffer is still empty. - It is not a timing issue where the buffer only filled later in the frame and thus appears empty before. The buffer has elements in it for many frames before I try to query it. I can verify this through the inspector.
linkedEntity
was originally instantiated from a prefab. It has components likeEntityGuid
on it.
What could be the reason for the buffer not containing any elements?