I noticed that every now and again in a collision listener the event.contact field is nil. The docs don’t mention anything about this, so I was wondering what cases cause this and whether it’s an indicator that there’s a bug in my code?
There’s a variety of other dynamic objects and static objects in the world. Could it be that if it collides with an object marked as a sensor that there’s no contact object?
When I added the print statement I did notice that occasionally event.contact was nil. I did add the following line:
[lua]
if not event.contact then
print (event.other,event.other.isSensor)
return
end
[/lua]
Which occasionally prints: table: 0x7fba1e4dd030 nil
Can you give me an estimate on the percentage of times it comes back as nil? Precollisions are very “sensitive” and often (potentially) fire many events right before the actual collision occurs. Most of these are redundant events which can be ignored or filtered out. Is the occasional time this occurs in your game causing issues in the physical behavior?
I haven’t done testing, but it’s possible that sensors don’t get the contact object. If this seems to be the case in your app, I’ll do a little testing and confirm if that is true or false and update the docs.
There’s a variety of other dynamic objects and static objects in the world. Could it be that if it collides with an object marked as a sensor that there’s no contact object?
When I added the print statement I did notice that occasionally event.contact was nil. I did add the following line:
[lua]
if not event.contact then
print (event.other,event.other.isSensor)
return
end
[/lua]
Which occasionally prints: table: 0x7fba1e4dd030 nil
Can you give me an estimate on the percentage of times it comes back as nil? Precollisions are very “sensitive” and often (potentially) fire many events right before the actual collision occurs. Most of these are redundant events which can be ignored or filtered out. Is the occasional time this occurs in your game causing issues in the physical behavior?
I haven’t done testing, but it’s possible that sensors don’t get the contact object. If this seems to be the case in your app, I’ll do a little testing and confirm if that is true or false and update the docs.