I have: public ComponentDataFromEntity<EntityData> ed; //How do I set another EntityData = ed???

In a CollisionJob: ICollisionEventsJob

I have:

public ComponentDataFromEntity ed;

I’m trying to clone the Entity Data struct by:

EntityData entityAd = ed;

//But this gives error:

NotImplementedException: The method or operation is not implemented.

EntityData.op_Implicit (Unity.Entities.ComponentDataFromEntity`1[T] v) (at Assets/Scripts/MoveEntities/Scripts/DataComponents/EntityData.cs:136)

ObstacleHitSystem+CollisionJob.Execute (Unity.Physics.CollisionEvent collisionEvent) (at Assets/Scripts/DOTS3/ObsticleHitSystem.cs:64)

Unity.Physics.ICollisionEventJobExtensions+CollisionEventJobProcess1[T].Execute (Unity.Physics.ICollisionEventJobExtensions+CollisionEventJobData1[T]& jobData, System.IntPtr additionalData, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at D:/unity/projectfiles/StarfighterGeneralOnSteam4/Library/PackageCache/com.unity.physics@0.6.0-preview.3/Unity.Physics/Dynamics/Simulation/ICollisionEventsJob.cs:112)


///AND BEFORE I TRIED TO USE AN AUTOSUGGEST by visual studio it was saying this error:

Cannot implicitly convert type ‘Unity.Entities.ComponentDataFromEntity’ to ‘EntityData’

Thanks guys, I’m actually at a walking pace with this stuff… ECS is actually getting kinda fun. I’ll be flying soon.

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);
1 Like

I have my code here: using Unity.Entities;using Unity.Physics;using Unity.Collections;using Uni - Pastebin.com

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.

Oh weird… It isn’t even like the native array implementation which allows you to clone structs by using =…

I think all I need to do is clone the entire string one element at a time… Tedius, but this needs done.

The answer may be:

EntityData entityAd = new EntityData();

entityAd= ed[entityA];//0 nothing //1chase and shoot //2stand still and shoot //3standstill

like this ed holds an array I guess, of collision elements… Weird, lets see if it rolls.

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.

1 Like

Here is an example of how i read some CollisionEvents for my Ability System:

public class CollisionBufferEventWriterSys : SystemBase
{
    [RequireComponentTag(typeof(CollisionInfoBuffer))]
    private struct ProcessCollisionsJob : ICollisionEventsJob
    {
        public BufferFromEntity<CollisionInfoBuffer> CollisionInfoBufferFromEntity;
        public void Execute(CollisionEvent collisionEvent)
        {
            Entity entityA = collisionEvent.EntityA;
            Entity entityB = collisionEvent.EntityB;
          
            if (CollisionInfoBufferFromEntity.HasComponent(collisionEvent.EntityA))
            {
                CollisionInfoBufferFromEntity[collisionEvent.EntityA].Add(new CollisionInfoBuffer { Value = entityB });
            }
          
            if (CollisionInfoBufferFromEntity.HasComponent(collisionEvent.EntityB))
            {
                CollisionInfoBufferFromEntity[collisionEvent.EntityB].Add(new CollisionInfoBuffer {Value = entityA});
            }
        } 
    }

    private BuildPhysicsWorld buildPhysicsWorld;
    private StepPhysicsWorld stepPhysicsWorld;

    protected override void OnCreate()
    {
        buildPhysicsWorld = World.GetOrCreateSystem<BuildPhysicsWorld>();
        stepPhysicsWorld = World.GetOrCreateSystem<StepPhysicsWorld>();
    }

    protected override void OnUpdate()
    {
        BufferFromEntity<CollisionInfoBuffer> collisionInfoBufferFromEntity = GetBufferFromEntity<CollisionInfoBuffer>();

        Dependency = new ProcessCollisionsJob
        {
            CollisionInfoBufferFromEntity = collisionInfoBufferFromEntity
        }.Schedule(stepPhysicsWorld.Simulation, ref buildPhysicsWorld.PhysicsWorld, Dependency);
    }
}

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.”