Unity 5.5 Bug? BCE0005: Unknown identifier: 'NavMeshAgent'.

var target : Transform; var moveSpeed = 3; var rotationSpeed = 3; var range : float=10f; var range2 : float=10f; var stop : float=0; var myTransform : Transform;

function Awake()
{
myTransform = transform;
}

function Start()
{
target = GameObject.FindWithTag(“Player”).transform;

}

function Update () {

GetComponent(NavMeshAgent).destination = target.position; <----- Problem/error
//rotate to look at the player
var distance = Vector3.Distance(myTransform.position, target.position);
if (distance<=range2 && distance>=range){
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
}

else if(distance<=range && distance>stop){

//move towards the player
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeedTime.deltaTime);
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
else if (distance<=stop) {
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed
Time.deltaTime);
}

}

This code works with unity 5.4 but not 5.5. Unsure why too.

When performing a getComponent, the type is passed as the type parameter, not as a regular parameter.

GetComponent<NavMeshAgent>().destination = target.position;

Should behave the way you want it to.

PS- quote this post to see proper code formatting.

Please post code properly, or it’s almost impossible for others to help!

Already stated and already helped.

Except you didn’t! OP’s using UnityScript, where your syntax won’t work - they’re using the us equivalent of GetComponent(typeof(NavMeshAgent)). Also it seems like OP’s not got any #using strict going on, so the duck typing takes care of calling .destination on GetComponent(Type)'s return value.

@o0neza0o , from 5.5 and forwards, NavMeshAgent lives in UnityEngine.AI instead of UnityEngine, so you’ll have to import that. It’s just this on top of your script:

import UnityEngine.AI;

… I believe, my UnityScript isn’t very good.

I’m not sure if it’s a bug that Unity fails to update UnityScript, or if this is just a bit of silent deprecation. For C# code, all instances of NavMeshAgent gets automatically replaced with UnityEngine.AI.NavMeshAgent on update.

2 Likes

Oh, my bad! I didn’t even notice it was unity script.

yeah sorry bout the posting code still trying to work this part of the site out XD. I never knew about that. I’m gonna try that :slight_smile:

It’s not the first time I’ve seen the auto updater fail on UnityScript. It wouldn’t surprise me if its another quiet internal decision towards deprecating UnityScript.

this is also in JS :confused: XD

I have this code in C# but just doesn’t have the navmesh agent

Its the using statement. In C# you should have using UnityEngine.AI; at the top of your script. In UnityScript the equivalent statement is import UnityEngine.AI;

yeah, it works now… Only thing is i can’t view the range in the inspector :confused:

Things in the inspector show only if they are public (for example, public string ShowHere; ) or have this:

[SerializeField]
private string ShowHere;