stride3d / stride

Stride (formerly Xenko), a free and open-source cross-platform C# game engine.
https://stride3d.net
MIT License
6.51k stars 942 forks source link

[Physics] PhysicsComponent Attach() ignoring existing ColliderShape #463

Open Eideren opened 5 years ago

Eideren commented 5 years ago

Release Type: Latest

Version: Latest

Platform(s): Any

Describe the bug Quoting sebl on Discord "Hello, i'm currently trying to create a physicscomponent from code. although i set a collidershape, it doesn't get added to the component. i think the reason is somewhere here the NativeCollisionObject is null, so the collidershape doesn't get added.

so, maybe anyone has an idea of what i am missing here? also, i get this error in the log: 'Entity xyz has a PhysicsComponent without any collider shape'"

so, maybe anyone has an idea of what i am missing here? also, i get this error in the log: 'Entity xyz has a PhysicsComponent without any collider shape'

To Reproduce

StaticColliderComponent sc = new Xenko.Physics.StaticColliderComponent();
BoxColliderShape bcs = new Xenko.Physics.BoxColliderShape(False, SomeSize);
sc.ColliderShape = bcs;

Once the engine hits PhysicsComponent.Attach It checks for if (ColliderShapes.Count == 0) and returns immediately afterwards without checking for an existing ColliderShape.

Additional context I'll be taking care of this issue through this PR.

pryvyd9 commented 1 year ago

The error still persists. Is there a solution to this?

myEntity.GetOrCreate<StaticColliderComponent>().ColliderShapes.Add(new StaticMeshColliderShapeDesc { Model = myModel });

'Entity Entity has a PhysicsComponent without any collider shape'