Fixing CS1503: Argument ‘#2’ cannot convert ‘UnityEngine.ForceMode’ expression to type ‘UnityEngine.ForceMode2D’

Fixing CS1503: Argument '#2' cannot convert 'UnityEngine.ForceMode' expression to type 'UnityEngine.ForceMode2D'

There is a common mistake for Unity3d newcomers when they are trying to implement jumping action in a 2D game. This error has code CS1503 and says that you¬†cannot convert ‘UnityEngine.ForceMode’ expression to type ‘UnityEngine.ForceMode2D’.

Fixing CS1503¬†cannot convert ‘UnityEngine.ForceMode’ expression to type ‘UnityEngine.ForceMode2D’

The fix is very simple. If you get this error it means that you’re calling the AddForce method of RigidBody2D object. And when you specify the Force Mode don’t forget to use class ForceMode2D (not just ForceMode class). This class was created directly for RigidBody2D.

Otherwise you will see the same error.

Example of using ForceMode2D

This is an example of usage from the real 2D game

rb2d.AddForce (Vector2.up * jumpSpeed, ForceMode2D.Impulse);

Leave a Reply

Be the First to Comment!