- Home /
some prefab collisions randomly stop working
My game has been working fine but, all of a sudden, some prefab collisions stop working. Usually, colliding with the player collects the prefab objects and processes them by tag; but, sometimes, only some prefabs with some tags work. It's always the same tags that stop working but I have no idea why, why it's not consistent, and if the tags have anything to do with the issue at all. When trying to test on my mobile device, the error always occurs on build. Nothing in the collider code has changed since it worked. I'm very confused.
Has anyone else run into this issue? If so, what should I look into?
Answer by Poon-Moon · Apr 11, 2019 at 06:13 PM
I've only experienced that when the objects move too fast and I've not had Continuous collision detection. If that is set, I guess you've checked the physics matrix of what's allowed to collide with what? And have you popped a debug on OnCollision and OnCollider - just incase one starts to fire in favour of the other?
I'll look into debugging. I'm just very confused because it worked fine until I opened it up and it stopped all of a sudden. Thinking about it, it seemed to work until I did the build. In your experience, has that impacted things at all? Strange that it only applies to specific tagged prefabs...
It turned out that when I migrated and changed some pieces of my project, I neglected to change collision detection to continuous. Thank you!
Answer by surfuay · Apr 12, 2019 at 01:57 AM
few possible things
sounds like you're using "gameObject.Find" or "gameObject.FIndWithTag" both of which have a tendency to get easily lost in consistency in your code. If that's the case I would recommend removing those and moving towards singletons.
your code would be a little clean so instead of
_player = gameObject.Find("Player").GetComponent
it would simply become Player.player.getCoins() (or whatever part of the player or other script your trying to access)
the other thing could be how you're calling the collision. One of the things that's thrown my games is in my 2D games i would add a Collider (incorrect) and then call it OnCollider2D (correct). So I had a collider and i was calling a collider but they were in different worlds. I would check your items that have colliders and make sure they're both 2D or not.
Your answer
![](https://koobas.hobune.stream/wayback/20220612195301im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Change value one prefab NOT ALL 2 Answers
detect if collider is not touching anything 0 Answers
Getting a Raycast to Classify Objects as the Same Thing 0 Answers
Raycast ignoring tags problem 1 Answer