It would really help if you could use the embed code function and post the pieces of setting up a job, and portions of the job relevant to your questions, as several other forum members suggested in other threads you opened. So at the risk of missing your question like others and similarity getting dinged on the head for the potentially failed attempt to offer help for free, here what I wonder: Did you actually GetComponenDataFromEntity to fill the array, before you clone it?
ComponentDataFromEntity<SampleComponent> allSampleComps = GetComponentDataFromEntity<SampleComponent>(true);
JobHandle job = Entities
.WithReadOnly(allSampleComps)
.ForEach((Entity entity) =>
{
if (allSampleComps.Exists(entity))
{
SampleComponent sampleComp = allSampleComps[entity];
Debug.Log($"{entity} has SampleComponent with value = {sampleComp.Value}");
}
}).Schedule(inputDeps);
It worked before to set a single long lastCollide; on a component called CollisionData(for time of collide). I would merely do: CollisionData c=new CollisionData(); c.lastCollide=time; then set it via command buffer.
But I ran into the 9 limit of a .foreach in another systembase, so I am trying to jam that lastCOllide into Entitydata… And that requires rewriting all of EntityData. I thought cloning a struct is just declaring a struct and putting the other one as the value… I probably don’t know datatypes is going on here.
The problem is I can’t make a new struct and get the data from the old struct(IcomponentData)
Probably should be easy for some…
Edit: Oh it looks like what I am feeding it isn’t even EntityData, but ComponentDataFromEntity CollisionJob ed… weird.
GetComponenDataFromEntity get you access to all the chunks having this component. You access the component of a given entity using the entity as index, as you tried with ed[entityA]. If you are not certain this entity has this component, then check that first (HasComponent(entity)
). Once you have the component, modify it as you modify any struct. You also need to remove the [ReadOnly] when accessing the CDFE. If you google search GetComponenDataFromEntity or search this forum you find plenty of actual code showing how it’s done if this was too cryptic. Good luck.
All you need to do in your case is to swap out BufferFromEntity with ComponentDataFromEntity.
Nobody wants to read through badly formatted and not color coded code. Pastebin is not an acceptable way to share code snippets to discuss. Please use the Code Tags in the future and try to extract the essential problem in a short example.
Thank you for responding, but my issue was different. For some reason I could not allocate a struct and set it to another struct. It had nothing to do with my code, Unity or DOTS. It was some random visual studio issue I fixed. That’s one of the biggest problem with working with cutting edge stuff that you can never be too sure if the bug that arose is something you did, a bug in the cutting edge stuff or a bug in the editor.
My confidence level in software engineering dropped significantly when my old video game in the 90s stopped working when I went from a 486 to a 586. I experienced the Pentium floating point division error first hand. I kept telling myself,“Computers can never be wrong while thinking,‘But this computer is not doing math right!’” It took me weeks before I updated my tens of thousands of lines of code to be compliant with the new normal we have of rounding errors. Then years later I realized this was for the best, for it speeds computation. The lesson learned is,“The more unknowns in an programming environment, the less certain you are on any cause of any issue.”