CS0029... But why, and what's the reason of this error? And how to correct it?

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class Helper : MonoBehaviour
{
    NavMeshAgent navMeshAgent;
    Zombie zombie;
    Helper helper;
    CapsuleCollider capsuleCollider;
    Animator animator;
    MovementAnimator movementAnimator;
    float speed;

    // Start is called before the first frame update
    void Start()
    {
        speed = animator.SetFloat("speed", navMeshAgent.velocity.magnitude);
        navMeshAgent = GetComponent<NavMeshAgent>();
        zombie = FindObjectOfType<Zombie>();
        navMeshAgent.updateRotation = false;
        capsuleCollider = GetComponent<CapsuleCollider>();
        animator = GetComponentInChildren<Animator>();
        movementAnimator = GetComponent<MovementAnimator>();
    }

    // Update is called once per frame
    void Update()
    {
        if (speed == 0) {
            zombie = FindObjectOfType<Zombie>();
        }
        navMeshAgent.SetDestination(zombie.transform.position);
        transform.rotation = Quaternion.LookRotation(navMeshAgent.velocity.normalized);
    }
}

CS0029: Cannot implicitly convert type ‘void’ to ‘float’ (19,17)

I think your error is in a different file. What file does the error say it’s in?

The error says that it’s in this file (above)

Why do you think it’s in different file?

Because I copied your script into Visual studio and didn’t see any errors except that Zombie, Helper, and MovementAnimator are undefined (I don’t have scripts with those names). Didn’t see your error. And I personally don’t see any compile issues with what you posted here. Did you forget to save changes to the file maybe?

error in
speed = animator.SetFloat(“speed”, navMeshAgent.velocity.magnitude);

use
animator.SetFloat(“speed”, navMeshAgent.velocity.magnitude);

1 Like

Assets\Scripts\Helper.cs(14,11): warning CS0649: Field ‘Helper.speed’ is never assigned to, and will always have its default value 0

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class Helper : MonoBehaviour
{
    NavMeshAgent navMeshAgent;
    Zombie zombie;
    Helper helper;
    CapsuleCollider capsuleCollider;
    Animator animator;
    MovementAnimator movementAnimator;
    float speed;

    // Start is called before the first frame update
    void Start()
    {
        animator.SetFloat("speed", navMeshAgent.velocity.magnitude);
        navMeshAgent = GetComponent<NavMeshAgent>();
        zombie = FindObjectOfType<Zombie>();
        navMeshAgent.updateRotation = false;
        capsuleCollider = GetComponent<CapsuleCollider>();
        animator = GetComponentInChildren<Animator>();
        movementAnimator = GetComponent<MovementAnimator>();
    }

    // Update is called once per frame
    void Update()
    {
        if (speed == 0) {
            zombie = FindObjectOfType<Zombie>();
        }
        navMeshAgent.SetDestination(zombie.transform.position);
        transform.rotation = Quaternion.LookRotation(navMeshAgent.velocity.normalized);
    }
}

RLY? Why is it?

That’s because you’re never changing the value of “speed”. It’s just a warning though. The game should run, it just won’t behave the way you want.