Best way to reproduce OnCollisionEnter2D call

I made my own custom character movement. When I move my character, I do a cast of the rigidbody2D to move it correctly, so it will not go through a wall. Because of that, no collision happens, therefore OnCollisionEnter2D is never called. At first, I solved this by using the SendMessage function to call a method that I made to imitate the call to OnCollisionEnter2D.

But now, I want to use a better solution. I couldn’t find if it was possible to force a call to OnCollisionEnter2D. I also looked up UnityEvents, but it would mean that anything that wants to be aware of a collision, with the player, would need to get the player first just to get the event and then say which method to call when that happen. I find that to be needlessly to much work.

The best solution I found so far is to have an interface on each gameobject that would want to be warned when a collision happens and have my character movement call that interface when a collision happens. Is there a better way, or this is the best I could hope for?

After some reflection, it was an interesting idea, but it would have been complicated to send data to the hitted object (a collision object with info such has normal, velocity, etc). In the end, I went for creating an interface, that all scripts that want to receive hit messages, must implement. In my scenario, that really is the best solution. Ultimately, the real best solution would be to actually use Unity physics to be able to simply directly use OnCollisionEnter2D, but, for my case, I will do that has a last resort solution. Thanks for everyone helps! :slight_smile: