Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

JavaScript communication with SendMessage and an int parameter that equals 0

Discussion in 'WebGL' started by bdovaz, Oct 16, 2015.

  1. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,016
    I have a problem.

    If I have a parameter that equals "0" and it does a conversion that it thinks I'm not passing any parameter and it fails:

    Application.ExternalEval("SendMessage(\"Example\", \"TestMethod\", "JSMethodThatReturnsZero()");");

    MissingMethodException: The best match for method TestMethod has some invalid parameter.

    // Unity side
    void TestMethod(string parameter) {
    }

    I think is the same problem that when on Unity side we do:

    SendMessage(go, "MethodName", null);

    We can't pass "null" because is the same as no parameters.

    The only workaround I see is to pass it as string and doing a cast on Unity side.
     
  2. mnml_

    mnml_

    Joined:
    Jun 17, 2015
    Posts:
    44
    just from the syntactic looks of it, shouldn't it be more something along the lines

    Application.ExternalEval("SendMessage(\"Example\", \"TestMethod\", " + JSMethodThatReturnsZero() + ");");

    or even

    SendMessage("Example", "TestMethod", JSMethodThatReturnsZero());


    ??
     
  3. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,016
    It was a manually typed example.

    I'm talking that passing an argument with 0 for Unity it expects a method with no arguments.
     
  4. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    This sounds like a bug. Could you file a bug report with a repro case? Then we will take a look.