Run cloud script from Untiy


#1

Hi,
How can I run cloud script from Unity?
I’m trying do something like this:

public void CreateCharacter(string nickname) {
var request = new RunScriptRequestDesc("CREATE_NEW_CHARACTER");
request.Params.Add("nickname", nickname);
ChilliConnectManager.Instance.SDK.CloudCode.RunScript(request,
	(scriptRequest, response) => { OnCharacterCreated?.Invoke(); },
	(scriptRequest, error) => {
		Debug.Log("Error...");
	});

}

I’m getthing following error message:
NullReferenceException: Object reference not set to an instance of an object
in line
request.Params.Add("nickname", nickname);


#2

I havent tried your specific example, but I believe it is when trying to do request.Params.Add(). Params is null until set. Usually I see building a dictionary of params, then set it request.Params = myParams;

It’s a little old, but there’s an example of this in one of our sample projects: https://github.com/ChilliConnect/Samples/blob/master/UnitySamples/Teams/Assets/Teams/TeamsSystem.cs#L92

Richard