- Home /
Objects placed manually collide, but don't if instantiated?
Yo,
I've been racking my brains for a day over this one. I have an explosion prefab which has a static trigger collider (no rigid body). I also have a turret prefab, with both a (non-trigger) box collider and a kinematic rigid body. According to the collision matrix , they should collide fine with each other.
Indeed, they do if I place them manually in the scene, on top of each other. As soon as the game starts, I can break in OnTriggerEnter() properly. However, if I instantiate them at run time, they utterly refuse to interact in any way.
Would anyone have any sort of idea as to what might be happening? Thanks!
Also, because they collide fine when placed manually, we can be sure that the layer-based collision matrix isn't the culprit.
Apparently, it might have something to do with my explosion script destroying the object within one frame. Once again, for some reason it works when the objects are created manually, but not at runtime.
The call order when the objects are instantiated manually is Awake(), OnTriggerEnter(), Update(), while on runtime instantiation, it's Awake(), Update(), OnTriggerEnter(). The code that destroys the explosion object is in Update(), so that makes sense.
Now, why is the order different? That's still a mystery.
Well dayum, I just don't get it. Sometimes it just works perfectly. I'm baffled.
so im confused, what exactly is supposed to happen, why does explosion prefab need to be static or for that matter have a collider.etc and how exactly are they interacting and supposed to be interacting
ps-the collision matrix isnt exactly spot-on, colliders have a rather finicky nature especially when it comes to hierarchy and overlapping colliders, oh and spawning colliders within or outside of colliders
Answer by microp · May 12, 2011 at 02:38 PM
I'm closing this question, as its description and my own torrent of comments make it more complicated than it should be.
Also, frustration.
See lil_billy's comment above for possible cause. I ended up working my way around all of this mess by using a SphereCast.
Your answer
Follow this Question
Related Questions
Collision not working at all [ABANDONED] 4 Answers
How to get collision point when using onTriggerEnter 5 Answers
How do i get OnTriggerStay2D to work? 1 Answer
Collisions - bounce of walls but not from characters (while still reacting with them) 0 Answers
Can't add Rigidbody component because collision prevents it 2 Answers