#Changing an entity's position from MonoBehaviour - surely this should be simple?

1 messages · Page 1 of 1 (latest)

raven night
#

Hey all, as the title suggests - how do?

Below is my attempt... I have a reference to the entity (a basketball) stored in my MB script, I can change velocity with this method just fine, but when I change position, the basketball vanishes. Interestingly, its collider moves fine, even the shadow its casting on the floor, but not the actual basketball instead. If I look at the entity in the inspector, I can see that as soon as I override the transform position, the ChunkWorldRenderBounds changes its extents to (0,0,0)

    private void SetLinearVelocity(Vector3 vel) //Works fine, happy rainbows and sunshine
    {
        ECSWorld.DefaultGameObjectInjectionWorld.EntityManager.SetComponentData(entity, new PhysicsVelocity
        {
            Linear = vel,
            Angular = GetAngularVelocity(),
        });
    }

    private void SetPosition(Vector3 pos) //Breaks the rendering on the entity - madness, badness & sadness
    {
        ECSWorld.DefaultGameObjectInjectionWorld.EntityManager.SetComponentData(entity, new LocalTransform
        {
            Position = pos,
            Rotation = GetRotation()
        });
    }

Also, when I override the transform, my entitiy's LocalToWorld component changes... the first three rows all get overriden to zeros, with the final column still being the expected transform position... I'm a little confused as to the relationship between LocalTransform, LocalToWorld, PostTransformMatrix, and the position of the collider

If I modify this to instead change the LocalToWorld component rather than LocalTransform, the rendering doesn't break, but the entity only moves for a single frame, and then snaps right back to where it was

vast loom
#

scale isnt being set in the second method

#

should use LocalTransfrom.FromPositionRotation(pos,rot) in the future

#

also should be controlling data from systems and not monobehaviours, might get other people chiming in on this 🙂

raven night
#

Bugger, you're absolutely right, I'm forgetting the scale!
And yeah, I had assumed someone would give me the "control data from systems" line, I'm trying to create an MB interface for my ECS components for my dev team (largely students who are new to programming, the ECS learning curve is a bit intense), so they can still make use of ECS but without having to actually deal with ECS, so the call has to call from a MB script... I suppose I could store all these position overrides in some kind of buffer and then process the buffer in the system, but that seems like unneeded overhead?