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

[YarnCommand] with parameter Vector2 fails for unclear reason with "incorrect number of parameters" #288

Open
hsandt opened this issue Sep 11, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@hsandt
Copy link

hsandt commented Sep 11, 2024

What is the current behavior?
I defined a Yarn Command taking a Vector2 parameter:

using System.Collections;
using UnityEngine;

using Yarn.Unity;

public class MoveCharacterCommand : MonoBehaviour
{
  [YarnCommand("move_character")]
  public static void MoveCharacter(string characterName, Vector2 to, float duration)
  {
      // do stuff
  }
}

In the doc, Vector2 is not in the list of supported parameter types, so I would understand if it doesn't work.

The problem is that, whether I write in my script:
<<move_character CharacterName (1.0,1.0) 2.0>>
<<move_character CharacterName 1.0 2.0>>
or just
<<move_character CharacterName 2.0>>

I get error:

Can't call command move_character: incorrect number of parameters
UnityEngine.Debug:LogError (object)
Yarn.Unity.DialogueRunner:HandleCommand (Yarn.Command) (at ./Library/PackageCache/dev.yarnspinner.unity/Runtime/DialogueRunner.cs:862)

and that is not the error I'd expect.

Please provide the steps to reproduce, and if possible a minimal demo of the problem:
Copy-paste the command class above into some MoveCharacterCommand.cs script, and the script line above into some repro.yarn script.

What is the expected behavior?
I should have an error on parameter type Vector2 not being supported.

Or, if Vector2 is somewhat tolerated but skipped (defaults to (0, 0)) then passing 2 arguments instead of 3 should work.

Or, if Vector2 happens to be supported although not mentioned in doc, (1.0,1.0) should work.

Note: in the Yarn Spinner Commands preview window, I can see Vector2 listed in the parameter list, although it doesn't mean it's supported at runtime.

Or, if (1.0,1.0) is badly formatted, the error should be about bad format for conversion.

Ideally, the "incorrect number of parameters" error should mention the number of parameters passed vs expected. This would help me debug much more, and not just this Vector2 issue but even when all parameters are simple but I happened to miss one argument. I can open a feature request specifically to improve error messages if you want to tackle this separately.

Please tell us about your environment:

  • Yarn Spinner Version: 2.4.2
  • Unity Version: 6000.0.12f1

Other information

In my real project I actually use a coroutine, a command that returns IEnumerator, but it was easier to write a void return type for this issue.

I tried to look at source code returning Status CommandDispatchResult.StatusType.InvalidParameterCount in Actions.cs and I did find 2 different locations. In one, a custom error Message is set $"{this.Name} needs a target, but none was specified" but this is never shown in the console log so I cannot verify it. Maybe console should show the Message that is set along with Status?

@hsandt hsandt added the bug Something isn't working label Sep 11, 2024
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