When I tried to use OnCollisionEnter, the writer that the entity has control over is null. If I switch that code to use OnTriggerEnter, the writer is not null. Is this a bug or by design. I wanted to use OnCollisionEnter to retrieve the contact point of a collision.
An update on this issue. I’ve switched to just using OnTriggerEnter but I’ve noticed something else. If I spawn the entity as kinematic so it does not collide with anything, move the entity above the collider I want it to colide with, switch off kinematic and let it fall and collide with collider in scene, all is good. The writer is not null. But if the entity collides with something that is not the intended collider it seems like the writter is then shut off. From then on, I move the object and drop it onto the intended collider in the scene it tells me the writer is null.
Unity has a bit of a quirk with OnCollision and OnTrigger functions, as they will run even if the monobehaviour is disable.
So you will have to check for null writers in these 2 function types.
That part I understand but the issue with oncollision is the writter is never not null no mater what. As for the ontriggerenter, this doesn’t explain the odd behavior where the writer is null after first collision. I’m not disabling any scripts or state.
Here is a video of the issue.
@martijn During my troubleshooting I noticed that if the object started above the planter and I moved it away from the planter and dropped it, the seed would collide with the planter even if visually this did not happen. I confirmed btw, that the seed is moving away from the planter using the inspector.
It seems the issue is related to the way I’m moving the entity (which I am doing this way since I can’t figure out how to mimic what I was doing pre spatial 9 in spatial 9). I’m send commands to the entity with coordinates that the entity takes and uses to move itself. During this process, I set the entities rigidbody to be Kinematic and then non-Kinematic when I grab and release. If I avoid toggling the Kinematic boolean, the collision works fine but it’s very hard to move the entity due to gravity.
Does Spatial 9 not allow me to make the rigidbodies Kinematic? In order to move the object I would need to be able to change this.
Instead of moving the object though commands. Wouldn’t it be a better solution to make the client, that grabs the object, authoritative over its position component?
This way you are able to move the component lag less locally.
According to the unity documents:
Notes: Collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached.
Since your object will be kinematic while you move it around, this might be causing your issue?
Trigger events do not have the non-kinematic requirement.
@martijn I agree that gaining authority would be better. Can you weigh in on my other post where I’m trying to do just that?https://forums.improbable.io/t/delegate-entity-to-client-in-spatial-9/1368/20?source_topic_id=1523
As for the part of the unity docs you quoted, that wouldn’t effect this because One of the entities meets that requirement. The issue isnt that the trigger or collision not being called, it’s with the spatial writer being null sometimes and collision positing of the object in a spatial scene. If we can solve the other forum post then this all doesn’t matter tho.