Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

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

Discussion in 'Scripting' started by cfos27, Sep 2, 2023.

  1. cfos27

    cfos27

    Joined:
    Sep 23, 2022
    Posts:
    3
    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:

    Code (CSharp):
    1. using UnityEngine;
    2. using Cinemachine;
    3.  
    4. namespace AC
    5. {
    6.  
    7.     [RequireComponent (typeof (CinemachineMixingCamera))]
    8.     public class CinemachineMixerController : MonoBehaviour
    9.     {
    10.  
    11.         #region Variables
    12.  
    13.         private float[] originalWeights = new float[0];
    14.         private float[] targetWeights = new float[0];
    15.         private float transitionTime = 0f;
    16.         private float transitionDuration = 0f;
    17.         private CinemachineMixingCamera cinemachineMixingCamera;
    18.  
    19.         #endregion
    20.  
    21.  
    22.         #region UnityStandards
    23.  
    24.         private void Awake ()
    25.         {
    26.             cinemachineMixingCamera = GetComponent<CinemachineMixingCamera> ();
    27.         }
    28.  
    29.  
    30.         private void OnEnable ()
    31.         {
    32.             EventManager.OnFinishLoading += OnFinishLoading;
    33.         }
    34.  
    35.  
    36.         private void OnDisable ()
    37.         {
    38.             EventManager.OnFinishLoading -= OnFinishLoading;
    39.         }
    40.  
    41.  
    42.         private void Update ()
    43.         {
    44.             if (transitionTime > 0f)
    45.             {
    46.                 float lerpAmount = 1f - (transitionTime / transitionDuration);
    47.  
    48.                 int numCameras = targetWeights.Length;
    49.                 float[] actualBlends = new float[numCameras];
    50.                 for (int i = 0; i < numCameras; i++)
    51.                 {
    52.                     actualBlends[i] = Mathf.Lerp (originalWeights[i], targetWeights[i], lerpAmount);
    53.                     cinemachineMixingCamera.SetWeight (i, actualBlends[i]);
    54.                 }
    55.  
    56.                 transitionTime -= Time.deltaTime;
    57.  
    58.                 if (transitionTime <= 0f)
    59.                 {
    60.                     SnapToTarget ();
    61.                 }
    62.             }
    63.         }
    64.  
    65.         #endregion
    66.  
    67.  
    68.         #region PublicFunctions
    69.  
    70.         public float SwitchCamera (int channel, float duration)
    71.         {
    72.             int numCameras = cinemachineMixingCamera.ChildCameras.Length;
    73.             originalWeights = new float[numCameras];
    74.             targetWeights = new float[numCameras];
    75.  
    76.             bool weightsAreSame = true;
    77.             for (int i = 0; i < numCameras; i++)
    78.             {
    79.                 originalWeights[i] = cinemachineMixingCamera.GetWeight (i);
    80.                 targetWeights[i] = (i == channel) ? 1f : 0f;
    81.  
    82.                 if (originalWeights[i] != targetWeights[i])
    83.                 {
    84.                     weightsAreSame = false;
    85.                 }
    86.  
    87.                 if (duration <= 0f)
    88.                 {
    89.                     cinemachineMixingCamera.SetWeight (i, targetWeights[i]);
    90.                 }
    91.             }
    92.  
    93.             if (duration <= 0f || weightsAreSame)
    94.             {
    95.                 SnapToTarget ();
    96.                 transitionTime = 0f;
    97.                 return 0f;
    98.             }
    99.  
    100.             transitionTime = transitionDuration = Mathf.Max (0f, duration);
    101.             return transitionTime;
    102.         }
    103.  
    104.         #endregion
    105.  
    106.  
    107.         #region CustomEvents
    108.  
    109.         private void OnFinishLoading (int saveID)
    110.         {
    111.             if (transitionTime > 0f)
    112.             {
    113.                 transitionTime = 0f;
    114.                 SnapToTarget ();
    115.             }
    116.         }
    117.  
    118.         #endregion
    119.  
    120.  
    121.         #region PrivateFunctions
    122.  
    123.         private void SnapToTarget ()
    124.         {
    125.             int numCameras = targetWeights.Length;
    126.             for (int i = 0; i < numCameras; i++)
    127.             {
    128.                 cinemachineMixingCamera.SetWeight (i, targetWeights[i]);
    129.             }
    130.         }
    131.  
    132.         #endregion
    133.  
    134.     }
    135.  
    136. }
     

    Attached Files:

  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    37,210
    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.
     
  3. cfos27

    cfos27

    Joined:
    Sep 23, 2022
    Posts:
    3
    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?
     
  4. BABIA_GameStudio

    BABIA_GameStudio

    Joined:
    Mar 31, 2020
    Posts:
    492
    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.
     
    halley likes this.
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    37,210
    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.
     
  6. cfos27

    cfos27

    Joined:
    Sep 23, 2022
    Posts:
    3
    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?
     
  7. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,606
    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.

    Code (CSharp):
    1. delegate void AC.EventManager.Delegate_SaveID     (     int      saveID    )
    Just to make that clear what this line actually means:

    Code (CSharp):
    1.     delegate        void    AC.EventManager.Delegate_SaveID (   int       saveID  )
    2. //                |      |                 |                |          |          |
    3. //  define a new  |return|    namespace    |  type name     | argument | argument |
    4. //  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

    Code (CSharp):
    1.    EventManager.OnFinishLoading += ....
    2. //                   /|\
    3. //                    |
    4. //            right click here
    and in the context menu click "Go To Definition"
    upload_2023-9-3_1-7-29.png
    This should show you how this event is declared.
     
    wideeyenow_unity likes this.