RPG => 3rd person tutorial Chapter 35 ForceReceiver Invoke Error

Hello Brian.

Since this chapter I have an error in the ForceReceiver’s script (not ForceReciever :wink: ).

I’ve this message in the console:

Assets\Scripts\Movement\ForceReceiver.cs(65,54): error CS1501: No overload for method ‘Invoke’ takes 1 arguments

It’s in the AddForce method at the end of my script:

using UnityEngine;
using UnityEngine.AI;

namespace RPG.Movement
{
    public class ForceReceiver : MonoBehaviour
    {
        [SerializeField] private float drag = 0.3f;
        [SerializeField] private float minimumImpactVelocity = .1f;

        private CharacterController controller;       
        private NavMeshAgent agent;

        public event System.Action OnForceApplied;
        public event System.Action OnForceCompleted; 

        private void Awake()
        {
            controller = GetComponent<CharacterController>();
            agent = GetComponent<NavMeshAgent>();
        }

        private float verticalVelocity;

        private Vector3 impact;
        private Vector3 dampingVelocity;
        private bool forceActive;
        public Vector3 Movement => impact + Vector3.up * verticalVelocity;

        private void Update()
        {
            if (verticalVelocity < 0f && controller.isGrounded)
            {
                verticalVelocity = Physics.gravity.y * Time.deltaTime;
            }
            else
            {
                verticalVelocity += Physics.gravity.y * Time.deltaTime;
            }
            impact = Vector3.SmoothDamp(impact, Vector3.zero, ref dampingVelocity, drag);
            if (agent)
            {
                if (impact.sqrMagnitude < minimumImpactVelocity)
                {
                    impact = Vector3.zero;
                    agent.enabled = true;
                }
            }
            if (forceActive)
            {
                if (impact.sqrMagnitude < minimumImpactVelocity)
                {
                    impact = Vector3.zero;
                    forceActive = false;
                    OnForceCompleted?.Invoke();
                    if (agent) agent.enabled = true;
                }
            }
        }

        public void AddForce(Vector3 force, bool triggerKnockbackEvent = false)
        {
            impact += force;
            if (agent) agent.enabled = false;            
            if(triggerKnockbackEvent) OnForceApplied?.Invoke(force);
            forceActive = true;
        }
    }
}

Any Idea what is missing ?

Thank you.

François

Hi, scurrows.one can help.

@Brian_Trotter, can you help with this problem?

Take a closer look at your definitions for the events (above).
OnForceApplied is a System.Action, which does not take a parameter by itself. Fortunately, System.Action has several generics.
In this case, you’re wanting to pass a Vector3 (force) to the event.

public event System.Action<Vector3> OnForceApplied;
public event System.Action OnForceCompleted;
1 Like

Hello Brian, Nina.

Thanks for your feedback.

I’m actually in holiday and far away frop keyboard :wink:

I ‘ll check that at the end of the week.

I may miss something.

But for me i only copy/paste your code.

I’ll controle this.

Thank you and have a nice day.

François