Search Unity

Bug Why my NavMesh agents does not work after build?

Discussion in 'Editor & General Support' started by mfzenbilci, Aug 7, 2022.

  1. mfzenbilci

    mfzenbilci

    Joined:
    Mar 12, 2022
    Posts:
    1
    My agents do a great job in the editor for avoiding static and dynamic obstacles(carving) and finishing the platform but after I build it and they only stay where they are and they rotate some random locations different for each one.

    EDIT: I added a lineRenderer to show the path and it does not show up in the build even though they are created in the editor. Why would they stop path finding?

    Here is my OpponentController class that only sets the finishLine as destination on awake:
    ```

    using UnityEngine;
    using UnityEngine.AI;

    public class OpponentController : Competitor
    {
    [SerializeField] private NavMeshAgent agent;
    [SerializeField] private Animator anim;
    [SerializeField] private float _endPositionX = -23.54f;


    void Awake()
    {
    //agent.speed = Random.Range(1.0f, 2.0f);
    _startPosition = transform.position;
    Vector3 endPosition = new Vector3(GameManager.instance.finishLine.position.x, 0, Random.Range(_limitZ, _limitZ));
    agent.SetDestination(endPosition);
    }


    }

    ```

    and Competitor is just a MonoBehaviour that I created as a base class :
    ```
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class Competitor : MonoBehaviour
    {
    protected Vector3 _endPosition;
    protected float _limitZ;
    public Vector3 _startPosition;

    public void StartOver()
    {
    transform.position = _startPosition;
    }

    }

    ```
    How can I fix this? It was a case study for a job application and I got only one day to make it work.