command-line-api icon indicating copy to clipboard operation
command-line-api copied to clipboard

SetHandler error cannot convert from 'method group' to 'Action<FooStruct?>'

Open codingdave opened this issue 2 years ago • 4 comments

Seems like SetHandler cannot bind Option<A?>? with Handler(A a) when A is struct.

Please find the minimal sample over here, which has the exact code for a class and a struct where it is working for the class and failing for the struct with

error CS1503: Argument 2: cannot convert from 'method group' to 'Action<FooStruct?>'

codingdave avatar Mar 11 '23 21:03 codingdave

As a workaround I can return an object? that I can cast back to a FooStruct. This, obviously, is not a solution and far from being optimal.

codingdave avatar Mar 11 '23 21:03 codingdave

yo anyone wanna help me out? Ive got this problem on Unity where its telling me that it cannot covert method group "GetMouseButtonDown". On my project I made a gun and im trying to make it so that when you press the left mouse button it shoots. All my other code is already finished but this is my last obstacle, can anyone help?

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Gun : MonoBehaviour { public Transform bulletPoint; public GameObject bulletPrefab; public float bulletspeed = 10;

void Update()
{
    if (Input.GetMouseButtonDown)
    {
        var bullet = Instantiate(bulletPrefab, bulletPoint.position, bulletPoint.rotation);
        bullet.GetComponent<Rigidbody>().velocity = bulletPoint.forward * bulletspeed;
    }    
}

Lordylein avatar Mar 15 '23 12:03 Lordylein

yo anyone wanna help me out? Ive got this problem on Unity where its telling me that it cannot covert method group "GetMouseButtonDown". On my project I made a gun and im trying to make it so that when you press the left mouse button it shoots. All my other code is already finished but this is my last obstacle, can anyone help?

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Gun : MonoBehaviour { public Transform bulletPoint; public GameObject bulletPrefab; public float bulletspeed = 10;

void Update()
{
    if (Input.GetMouseButtonDown)
    {
        var bullet = Instantiate(bulletPrefab, bulletPoint.position, bulletPoint.rotation);
        bullet.GetComponent<Rigidbody>().velocity = bulletPoint.forward * bulletspeed;
    }    
}

Wrong repo for this question, but I think this is your answer.

Change:

if (Input.GetMouseButtonDown)

To:

if (Input.GetMouseButtonDown(0))

GetMouseButtonDown isn't a field or property, it is a method that takes an int (the button you're interested in) and returns a bool.

ian-buse avatar Mar 17 '23 00:03 ian-buse

Is the issue clear @adamsitnik ? I fear due to the hijacking above that the intention of this case got lost. To remind back to the reported issue: I cannot bind Option<A?>? when A is a struct. A class, however, is supported.

Kind regards Dave

codingdave avatar Jul 23 '23 09:07 codingdave