Passing a parameter by reference from JavaScript

I’m using a third party library written in c#, which has some functions that go like this:

void SomeFunction(ref string someParameter)

How can I call this function from JavaScript? I’m getting a parameter mismatch if I just put the variable in the caller.

You can do that directly but you may use some wrapper to achieve this:

// A C# Wrapper which you can name "StringHandler.cs"
public class StringHandler
   public void WrapperFunction(string[] str)
      // If you string need to be empty DO:
	  string localStr = "";
      // Or if your string should have some data DO:
      string localStr = str[0];

      // Now call the third party stuff
      ThirdPartyStuff.SomeFunction(ref localStr);
	  str[0] = localStr;

Now, in your javascript do stuff like the following:

var stringHandler : StringHandler;

function Start()
	var myStr : String[] = [ "YouBaseTextIfNeeded" ];

	Debug.Log("1) myStr = " + myStr[0]);

	stringHandler = new StringHandler();


	Debug.Log("2) myStr = " + myStr[0]);

Sounds like your variable isn’t the correct type? Because it works fine just calling a function and using the variable without “ref” in JS. e.g.,

using UnityEngine;

public class Test {
    public static void StringTest (ref string test) {
    	test = "abc";

And then with JS:

var test = "123";
Test.StringTest (test);
Debug.Log (test);