Sign In Register

How can we help you today?

Start a new topic
Answered

Unity messages

Hey!


I'm trying to send messages via CloudCode to my Unity project, but it doesn't seem to be receiving them or I'm sending them wrong. I've tried the following methods 

var mssg = Spark.message("msg_newMsg");
var ppl = [Spark.getPlayer()];

Spark.sendMessageByIdExt({"msgType": "text"}, mssg, ppl);
Spark.sendMessageExt({"msgType": "text"}, mssg, ppl);
Spark.message("msg_newMsg").setSendViaSocket(true).setPlayerIds(ppl).send();

 but none of them seem to have done anything. I made a custom scriptmessage for this named 'msg_newMsg' which has the socket on.

I did receive the challenge messages when I tried that.


What should I try next?


Best Answer
Could you try this by sending just a simple test message in your cloud-code?

Something like Spark.sendMessage({ "ID" : "THIS IS A TEST!" }, Spark.getPlayer());
You you can see this is the test-harness when you call it, you should be okay, but its hard to know the problem without knowing what kind of errors you are getting.

It doesn't look like there is a problem though, but there are a few things that could be going wrong.

1 - if you are sending the message through the test-harness while you have unity open then unity may be logged in as a different user to what you have on the test harness, and since your code only sends the message to the current user, your unity build will never get the message.

2 - I've noticed that if you have unity open and click onto another open program (like your browser, if you were to send the message through the test-harness) gamesparks will be disconnected and when you click back to unity it will immediately reconnect. However, you'll have missed the message. You can stop this from happening by pausing the unity game before you use the test-harness and then unpausing it and you should see the message come through.

The last thing is to make sure your message-listeners are setup correctly in your scripts.
You can see how to do that at the bottom of the unity-sdk page here -> https://docs.gamesparks.net/sdk/unity3d-sdk

Hope that helps,
- Sean

 

1 Comment

Answer
Could you try this by sending just a simple test message in your cloud-code?

Something like Spark.sendMessage({ "ID" : "THIS IS A TEST!" }, Spark.getPlayer());
You you can see this is the test-harness when you call it, you should be okay, but its hard to know the problem without knowing what kind of errors you are getting.

It doesn't look like there is a problem though, but there are a few things that could be going wrong.

1 - if you are sending the message through the test-harness while you have unity open then unity may be logged in as a different user to what you have on the test harness, and since your code only sends the message to the current user, your unity build will never get the message.

2 - I've noticed that if you have unity open and click onto another open program (like your browser, if you were to send the message through the test-harness) gamesparks will be disconnected and when you click back to unity it will immediately reconnect. However, you'll have missed the message. You can stop this from happening by pausing the unity game before you use the test-harness and then unpausing it and you should see the message come through.

The last thing is to make sure your message-listeners are setup correctly in your scripts.
You can see how to do that at the bottom of the unity-sdk page here -> https://docs.gamesparks.net/sdk/unity3d-sdk

Hope that helps,
- Sean

 

Login to post a comment