❔ Compiler cannot infer lambda return type

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using Cysharp.Threading.Tasks;

public class Title : MonoBehaviour
{
void Start() {
StartCoroutine(ShowTitles());
}

IEnumerator ShowTitles() {
string[] words = {"The", "White", "Christmas", "welcomes", "you!"};
foreach (var pack in words.Select((word) => {
var obj = GameObject.Find(word);
var render = obj.GetComponent<MeshRenderer>();
Material mat = render.materials[0];

var colour = mat.GetColor("_Color");
float H, S, V;
Color.RGBToHSV(colour, out H, out S, out V);
mat.SetColor("_Color", Color.HSVToRGB(H, S, 1));

return new {mat, H, S, V};
})) {
int x = 10;
for (int i=0; i < x; i++) {
yield return new WaitForSeconds(0.1f);

pack.mat.SetColor("_Color", Color.HSVToRGB(pack.H, pack.S, pack.V / (float)x));
}
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using Cysharp.Threading.Tasks;

public class Title : MonoBehaviour
{
void Start() {
StartCoroutine(ShowTitles());
}

IEnumerator ShowTitles() {
string[] words = {"The", "White", "Christmas", "welcomes", "you!"};
foreach (var pack in words.Select((word) => {
var obj = GameObject.Find(word);
var render = obj.GetComponent<MeshRenderer>();
Material mat = render.materials[0];

var colour = mat.GetColor("_Color");
float H, S, V;
Color.RGBToHSV(colour, out H, out S, out V);
mat.SetColor("_Color", Color.HSVToRGB(H, S, 1));

return new {mat, H, S, V};
})) {
int x = 10;
for (int i=0; i < x; i++) {
yield return new WaitForSeconds(0.1f);

pack.mat.SetColor("_Color", Color.HSVToRGB(pack.H, pack.S, pack.V / (float)x));
}
}
}
}
\Avatar\Title.cs(25,20): error CS1662: Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type
\Avatar\Title.cs(25,20): error CS1662: Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type
5 Replies
Kouhai
Kouhai11mo ago
Looks like Select isn't linq's Select? I don't see System.Linq namespace
危機紀元之子
Thank you. My code compiles now after importing the namespace.
jcotton42
jcotton4211mo ago
Why the hell are you using Select like that pepetense
危機紀元之子
Code too many Rust I just get used to people reviewing my Rust code as "iter hell".
Accord
Accord11mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts