- Home /
Rigidbody and collider Sendmessage delay error
Hey guys i have a slight problem, its not actually effecting gameplay but i dont like errors in my log =P. Anyways the problem is this. I have a projectile with a rigidbody attached and set to is Kinematic, and i have another object with a box collider and set as a trigger. When my projectiles OnTriggerEnter goes off i have it do a sendmessage to the collider if its tag is the right one which decrements thats gameobjects health. Now the problem is that my projectiles shoot in pairs so there are instances where when they collide into the trigger it only takes one of them to kill the trigger object thus deleting it. However the other projectile still attempts to sendmessage the trigger because both projectiles hit at the same time generally and generates SendMessage AdjustHealth has no receiver! error in my logs. Is this a huge issue to have in the warning logs or is this just some kind of unfixable/ not important error that i can leave alone?
I hope i described it well enough and thanks in advanced for your help!
Answer by Statement · Jan 08, 2011 at 10:18 AM
You probably use DestroyImmediate in your source of AdjustHealth. Try using Destroy instead, since it will postpone the deletion to the end of the frame, after your physics callbacks.
Another option would be to check the receiver for null and use SendMessageOptions.DontRequireReceiver.
If you're serious about your production, treat all warnings as errors. Fix them before going to bed. Don't take shortcuts. :)
HI statement and thanks for the reply, currently i am using destroy and not destroyimmediate on both objects. But i think the second option will fix the issue, cant really test it atm but i will get back to ya when i do. Thanks again!
Sorry to double post just wanted to thank you again Statement as this did fix the problem! I dont like anything in my log unless i put it there and it was bothering me lol thanks again man!
As long you know what you are doing when you are using DontRequireReceiver. It means that there is no longer any contract that there has to be a script handling the call. For many situations this is the case, but if you know that you always should expect some script to handle the call then you probably have another deeper problem. Don't worry, I wouldn't be answering questions if I didn't like helping out :)
Your answer
Follow this Question
Related Questions
Check for rigidbody presence when in collision with a trigger 2 Answers
Box Collider Trigger never being triggered. 0 Answers
How to enable gravity on gameobject when interact by player 3 Answers
How to get collision point when using onTriggerEnter 5 Answers
Rigidbody2D alternating between TriggerEnter and TriggerExit? 1 Answer