I'm doing some asynchronous caching and I'm using a simple Action callback to let the rest of the system know when the caching is complete.
The entry point (the line causing the error):
this.StartCoroutine<Action>(SceneUtils.CacheSceneNames, PopulateButtons);
Coroutine method:
public static IEnumerator CacheSceneNames(Action completedCallback) {}
Callback method:
private void PopulateButtons() {}
And finally, the method that starts the coroutine:
public static Coroutine StartCoroutine<T>(this MonoBehaviour extends, Func<IEnumerator, T> method, T value) {}
As far as I can tell all of the parameter and return types are correct, however I'm getting the following error:
error CS0123: A method or delegate `CacheSceneNames(System.Action)' parameters do not match delegate `System.Func<System.Collections.IEnumerator,System.Action>(System.Collections.IEnumerator)' parameters
Can anyone point out what I am doing wrong? Could this be a covariance issue?
I think you want to specify Func<T, IEnumerator> method
instead of Func<IEnumerator, T> method
in the parameter list of StartCoroutine<T>
.
It's Func<T, TResult>
: the return type is the last type parameter - and your CacheSceneNames
takes a parameter of Action
( T
) and returns IEnumerator
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.