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)
public class Mob : MonoBehaviour {
public CharacterController controller;
void Update ()
{
chase ();
}
void chase()
{
transform.LookAt (player.position);
controller.SimpleMove (transform.forward*speed);
}
}
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)
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.
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…
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 + * 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.
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.
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.
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.