Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YarnFunction-tagged methods that take converted types fail type checking #238

Open
desplesda opened this issue Jun 11, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@desplesda
Copy link
Contributor

What is the current behavior?

YarnFunction-tagged methods that take converted types do not type check correctly.

Please provide the steps to reproduce, and if possible a minimal demo of the problem:

The following Yarn Function will produce import errors when compiling:

[YarnFunction("test_function")]
public static bool TestFunction(GameObject gameObject) {
   return true;
}

While this function is understood by the runtime (a call to TestFunction("Player") would result in the first parameter being passed as any GameObject in the scene with the name "Player"), the conversion from GameObjects to strings is not made known to the type checker. This results in the following type checking error: Function test_function cannot be used in Yarn Spinner scripts: parameter gameObject's type (UnityEngine.Game0bject) cannot be used in Yarn functions.

What is the expected behavior?

The type checker should be informed that, in the context of Yarn scripts, the parameters of functions like this always have valid Yarn types.

Please tell us about your environment:

This error was reported in Yarn Spinner v2.3.0-beta2 by Discord user Tay.

@desplesda desplesda added the bug Something isn't working label Jun 11, 2023
@desplesda desplesda self-assigned this Nov 13, 2023
@desplesda
Copy link
Contributor Author

Looked into this. One way we can do this is to make the actions source code generator wrap all functions that take Unity type (like Component or GameObject) with a thunk that takes a string in place of the Unity type (and performs the work of converting from string to the Unity type, e.g. via a GameObject.Find).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant