help with CS0123 error "No overload for __ matches delegate ___"

Hi all, I’m extremely new to Unity and code in general, and I have this issue that’s preventing me from opening my file. What I understand is that it’s an issue stemming from how Cinemachine and Adventure Creator are interacting under the hood, and I know there’s something that isn’t communicating correctly between two parts of the code, but I simply don’t know enough about coding in general to be able to fix it myself. Could somebody help explain what I need to change and why (in as lay-person words as possible)? I included a screenshot of the error and code below. Greatly appreciate any and all help!

The error says:
Assets\AdventureCreator\Downloads\Cinemachine integration\Scripts\CinemachineMixerController.cs(32,36): error CS0123: No overload for ‘OnFinishLoading’ matches delegate ‘EventManager.Delegate_Generic’

And the code looks like this:

using UnityEngine;
using Cinemachine;

namespace AC
{

    [RequireComponent (typeof (CinemachineMixingCamera))]
    public class CinemachineMixerController : MonoBehaviour
    {

        #region Variables

        private float[] originalWeights = new float[0];
        private float[] targetWeights = new float[0];
        private float transitionTime = 0f;
        private float transitionDuration = 0f;
        private CinemachineMixingCamera cinemachineMixingCamera;

        #endregion


        #region UnityStandards

        private void Awake ()
        {
            cinemachineMixingCamera = GetComponent<CinemachineMixingCamera> ();
        }


        private void OnEnable ()
        {
            EventManager.OnFinishLoading += OnFinishLoading;
        }


        private void OnDisable ()
        {
            EventManager.OnFinishLoading -= OnFinishLoading;
        }


        private void Update ()
        {
            if (transitionTime > 0f)
            {
                float lerpAmount = 1f - (transitionTime / transitionDuration);

                int numCameras = targetWeights.Length;
                float[] actualBlends = new float[numCameras];
                for (int i = 0; i < numCameras; i++)
                {
                    actualBlends[i] = Mathf.Lerp (originalWeights[i], targetWeights[i], lerpAmount);
                    cinemachineMixingCamera.SetWeight (i, actualBlends[i]);
                }

                transitionTime -= Time.deltaTime;

                if (transitionTime <= 0f)
                {
                    SnapToTarget ();
                }
            }
        }

        #endregion


        #region PublicFunctions

        public float SwitchCamera (int channel, float duration)
        {
            int numCameras = cinemachineMixingCamera.ChildCameras.Length;
            originalWeights = new float[numCameras];
            targetWeights = new float[numCameras];

            bool weightsAreSame = true;
            for (int i = 0; i < numCameras; i++)
            {
                originalWeights[i] = cinemachineMixingCamera.GetWeight (i);
                targetWeights[i] = (i == channel) ? 1f : 0f;

                if (originalWeights[i] != targetWeights[i])
                {
                    weightsAreSame = false;
                }

                if (duration <= 0f)
                {
                    cinemachineMixingCamera.SetWeight (i, targetWeights[i]);
                }
            }

            if (duration <= 0f || weightsAreSame)
            {
                SnapToTarget ();
                transitionTime = 0f;
                return 0f;
            }

            transitionTime = transitionDuration = Mathf.Max (0f, duration);
            return transitionTime;
        }

        #endregion


        #region CustomEvents

        private void OnFinishLoading (int saveID)
        {
            if (transitionTime > 0f)
            {
                transitionTime = 0f;
                SnapToTarget ();
            }
        }

        #endregion


        #region PrivateFunctions

        private void SnapToTarget ()
        {
            int numCameras = targetWeights.Length;
            for (int i = 0; i < numCameras; i++)
            {
                cinemachineMixingCamera.SetWeight (i, targetWeights[i]);
            }
        }

        #endregion

    }

}

It is complaining that the thing you are trying to attach (in this case the OnFinishLoading() function) has the wrong function signature for what that EventManager.OnFinishLoading delegate is expecting.

Think of it as “it wants an orange, you’re giving it an apple.”

Is EventManager part of that adventure toolkit? Go check what “shape” of function it expects you to attach.

This is what I mean by “shape” or “signature”:

From your code above, you are attaching a function that takes an integer and returns nothing (void).

Most likely it only supports a function that takes nothing and returns nothing.

I’m not sure if EventManager is part of the Adventure Creator toolkit or something else, let me look into that.

Another probably extremely basic question, but how do you know that the function from the code is taking an integer and returns nothing?

In the following function definition:
private void OnFinishLoading (int saveID)
the void is the return type, and effectively means nothing. If it was returning something else, it would be another type (eg: int, float, etc.)
and whatever is within the () of the function is what is being passed into it. In this case it is int saveID.

Function definitions are some of the most basic things you need to know, so you really should be looking through some of the Unity Learn lessons where the basics are explained.

1 Like

It kinda depends.

Sometimes they use an action / function and the declaration might look like:

public System.Action OnFinishLoading;

They can even tack the keyword event in there for different functionality.

Or they might declare a delegate type with the delegate keyword.

Start by right-clicking on the second word in EventManager.OnFinishLoading and say “take me to definition” or whatever pops up in your code editor.

As an adjunct, try to find where that EventManager is. I’m guessing it’s part of that other thing you mentioned.

Thanks for your answers, they’ve been incredibly helpful so far and I really appreciate your patience, and I’ve confirmed that yes the EventManager is from Adventure Creator.

What next steps would you recommend I take to fix this issue?

Well, you should check what type that EventManager.OnFinishLoading event actually has… First of all, are you sure you actually saved all your files and that the code you posted is actually the current code? According to the documentation of that toolkit that event is of type Delegate_SaveID. So when you check that delegate type it is defined as it should be and your code should not throw any error.

delegate void AC.EventManager.Delegate_SaveID     (     int      saveID    )

Just to make that clear what this line actually means:

    delegate        void    AC.EventManager.Delegate_SaveID (   int       saveID  )
//                |      |                 |                |          |          |
//  define a new  |return|    namespace    |  type name     | argument | argument |
//  delegate type | type |                 |                |   type   |   name   |

Note that from your error we can actually read that whatever event you actually deal with is of type EventManager.Delegate_Generic.

So either you use a newer or older version of that toolkit and they changed the event type, or your code is not saved and not the actual code that is compiled. The Delegate_Generic is just a callback without any arguments.

When you use visual studio, you can simply right click on the event “OnFinishLoading” in your code

   EventManager.OnFinishLoading += ....
//                   /|\
//                    |
//            right click here

and in the context menu click “Go To Definition”
9268746--1297536--upload_2023-9-3_1-7-29.png
This should show you how this event is declared.

1 Like