Search Unity

CharacterController.Move called on inactive controller

Discussion in 'Scripting' started by VandalPwoof, Aug 18, 2017.

  1. VandalPwoof

    VandalPwoof

    Joined:
    Feb 17, 2017
    Posts:
    23
    So, I'm following a tutorial on a Diablo-esque game that is made in Unity 4. However, I am unable to make the enemy nor the player move with this piece of code. Furthermore, the error log states that the CharacterController.Move has been called on an inactive controller, even though it is right there in the inspector? Can someone help please? I checked the similar topics and no one has answered the similar issue.

    Error Log:
    CharacterController.Move called on inactive controller
    UnityEngine.CharacterController:SimpleMove(Vector3)

    Code (CSharp):
    1. public class Mob : MonoBehaviour {
    2.     public CharacterController controller;
    3.  
    4.     void Update ()
    5.     {
    6.         chase ();
    7.     }
    8.  
    9.     void chase()
    10.     {
    11.         transform.LookAt (player.position);
    12.         controller.SimpleMove (transform.forward*speed);
    13.     }
    14. }
     
  2. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    Then it may just be disabled (the little checkbox on every component). If you want to make sure it's enabled
    put
    Code (CSharp):
    1. void OnEnable(){ //or Awake() or Start()
    2.     controller.enabled = true;
    3. }
    in there
     
    Azuperfilito likes this.
  3. VandalPwoof

    VandalPwoof

    Joined:
    Feb 17, 2017
    Posts:
    23
    I tried setting it to true, but even when I try and playtest it...Unity is adamant in considering it inactive.
     

    Attached Files:

  4. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    Maybe it's not the enemy, but the player with its controller? (if you click on the message in the console, it should highlight the corresponding GameObject)
     
  5. VandalPwoof

    VandalPwoof

    Joined:
    Feb 17, 2017
    Posts:
    23
    Couldn't be, the component is under the enemy. I tried also to disable the player controller, so that the character controller is just on the enemy, but no luck.
     
  6. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    Do a Debug.Log(controller.enabled); to see what it returns. Maybe also check GameObject.activeSelf or activeInHierarchy
     
  7. VandalPwoof

    VandalPwoof

    Joined:
    Feb 17, 2017
    Posts:
    23
    Where and how should I put the code for activeSelf and activeinHierarchy?

    Assets/Scripts/Mob.cs(37,25): error CS0120: An object reference is required to access non-static member `UnityEngine.GameObject.activeSelf'

    I placed the Debug.Log (controller.enabled); in the chase() function. It returns True there.
    Now this is a huge contradictory mess of trues and falses from Unity. All I want to do is to make the enemy follow the player...
     
  8. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    Debug.Log(controller.gameObject.active[self/InHierarchy])
     
  9. Rob-Hafey

    Rob-Hafey

    Joined:
    Jul 24, 2014
    Posts:
    12
    I have been plagued with this problem and I accidentally just got a clue why this was happening in my application. Try going to the character controller and changing the "step offset" variable. Mine was .3 and I changed it to something bigger like .35. This uncovered the following error msg...

    "Step Offset must be less or equal to <scaled Height> + <scaled Radius> * 2"

    Even if I reset it back to it's original value of .3 I still got the error. Once I changed my step value to something that didn't give me an error (in my case .1) my controller started working again. My suspicion is that a U4 step offset value was not compatible with U5 but no warning was generated to that effect after the upgrade.
     
    BE_Foge, Du-An-20, c_hirschi and 5 others like this.
  10. wkyburz

    wkyburz

    Joined:
    Apr 25, 2018
    Posts:
    1
    Rob-Hafey, you are God sent. Thank you. step offset = .1 did the trick
     
  11. bakhtyar-khan

    bakhtyar-khan

    Joined:
    Oct 27, 2017
    Posts:
    2
    Love U Thanks that works but on 0.22
     
  12. Deleted User

    Deleted User

    Guest

    I had the same issue, making the player bigger it's been solved for people who still have this issue.
     
    dchacke likes this.
  13. Bisrategebriel

    Bisrategebriel

    Joined:
    Sep 22, 2020
    Posts:
    1
    Making Step Offset to 0.1 works ...Thanks to Rob-Hafey
     
  14. dchacke

    dchacke

    Joined:
    Apr 6, 2021
    Posts:
    3
    dragon_script's advice worked for me (making the player bigger). In my case, I used a package from the asset store and when I dragged the player prefab onto the scene, it was tiny and therefore couldn't move. It's worth checking your prefab's size after incorporating it in your scene.
     
  15. Hulgan

    Hulgan

    Joined:
    Jan 21, 2021
    Posts:
    1
    I had this issue occur because I was disabling all my rigidbodies in the start method. The character controller is considered a rigidbody so if you have any code that disables it, it'll cause this issue.
     
  16. c_hirschi

    c_hirschi

    Joined:
    Apr 21, 2021
    Posts:
    1
    8 years later, and your protip is still useful :) thanks @Rob-Hafey
     
    BE_Foge likes this.
  17. GoosDev

    GoosDev

    Joined:
    Apr 18, 2022
    Posts:
    1
    I came here because I was having a similar issue, but funilly enough, my Unity crashed and that somehow fixed the issue.
     
  18. MrMcFlurry

    MrMcFlurry

    Joined:
    Jul 28, 2022
    Posts:
    1
    You can also just do the math. look at what you have your hight and radius set to in your "Character Controller" (Mine was set to 0 for both). Then add the height and the radius and multiply the solution by 2. The number you get is what you should set the step offset to. (Because my values were 0, I did 0 + 0 * 2 = 0. So I set my offset to 0 and it worked.
     
  19. stigmamax

    stigmamax

    Joined:
    Jun 30, 2014
    Posts:
    312
    MERCI !!!!!!!!!!!!!!!