Why can't i use CharacterController.move

Hi! I Just made a character controller based script which uses input.getaxis and charactercontroller.move but when I head into unity it returns this error

“Assets\Scrpits\PlayerMovement.cs(24,20): error CS1061: ‘CharacterController’ does not contain a definition for ‘Move’ and no accessible extension method ‘Move’ accepting a first argument of type ‘CharacterController’ could be found (are you missing a using directive or an assembly reference?)”

I tried hundreds ways but it didn’t
work here my
script

From what I can tell IntelliSense hasn’t loaded properly. Are you using VSCode or Visual Studio? Does this error show up in the Unity console as well or just when you move your mouse over the red underline in the code editor?

I’m 90% certain that you called one of your own classes CharacterController. Indications for this are the missing namespace “UnityEngine” before the word “CharacterController” in the error message. So your own class is “hiding” the one that is shipped with Unity that is defined in the UnityEngine namespace.

There are generally three options here:

  • First rename or remove your own script which you called CharacterController to something else. This is what I would generally recommend. Avoid using class names of built-in types.

  • In some cases it might help to define your own class in a seperate namespace and not the global namespace. However this may not work for MonoBehaviours in some situations.

  • Last if you really want to keep your own class the way it is, your only alternative is to be more specific when you use the class name. In this case you either want

  • use UnityEngine.CharacterController whenever you need to specify the CharacterController type of Unity.

  • put a using alias at the top of your file to indicate which type you want to use inside this file: using CharacterController = UnityEngine.CharacterController;

As I stated I would highly recommend to rename your own class.

In case this is one of the remaining 10% of cases, we need more information on your issue. Do you get this error in the Untiy console? Because that’s the only place that really matters. If it compiles and works in Unity everything is fine. So if you just get this error inside your IDE (VisualStudio, VSCode, …) it’s not really an issue, just a misuse / misconfiguration of your IDE. Make sure you always open the “solution file” (.sln) that Unity generates when editing scripts. A solution is a project collection. A project file (.csproj) describes what files belong to a project and what external references are required / used by this project. If you just editing a single cs file, the IDE has no idea what those types mean.

1 Like