简体   繁体   中英

Unity: Changing velocity of RigidBody2D after collision causes game to crash regardless of platform, including in the editor

This line of code is single handedly causing my game to crash only sometimes. It essentially freezes the editor and I have to force quit Unity, and same on mobile.

_rb.velocity = new Vector2(_rb.velocity.x, -20f);

I've tried setting a flag in the collision and updating velocity on the next fixed update. I've tried updating the velocity directly in the EnterCollision2D method.

Notably I haven't been able to recreate the crash when applying force instead of altering velocity, but applying force doesn't give the desired effect.

The editor logs don't have anything in them either, so I'm pretty confused. Any help would be greatly appreciated!

Im pretty sure the collision isnt the poroblem here. Make sure you don't have any infinite loops in your code (calling the same method inside of the method or using while loops outside of coroutines). Also if you are using unity 2018 it tends to crash quite fast.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM