Super new to Gamelift, trying to run it Unity but running into some issues, help would be greatly appreciated

Hi all,

As previously stated, super new to GameLift/AWS in general. My team is trying to create a multiplayer experience and we’re hoping into integrate GameLift RealTime servers into our project. I’m trying to do a very basic messaging broadcasting, where User A types a string and hits a button and that message then appears for User’s B-Z in a chat box.

The RealTime Server was written in JavaScript and largely based on the megafrograce example
As I understand it you need to define op codes to send off to your realtime server, the server processes them and sends back data accordingly. In my Unity project and in my Server.JS file I’ve got an opcode for user messages. I’ve got a method for sending a message in my Unity scripts, looks something like this

public void SendMessage(){

       string MessagetoSend = Input.GetComponent<InputField>().text.ToString();

       Debug.Log(MessagetoSend);

       byte [] bytes = Encoding.ASCII.GetBytes(MessagetoSend);

       _client.SendEvent(MESSAGE_OP_CODE, bytes);

    }

When the method fires I see this pop up in the Unity

which makes me think the Data is firing off correctly. The confusion comes in server side,
in the onMessage I have the following defined

If I’m not mistaken that should send at least an Op Code back to my string, but my OnDataReceived Method (defined below) isn’t even showing up in the Unity console

I’m honestly not sure where I went wrong, my initial suspicions make me think it’s something wrong with how I defined the onMessage method in my JavaScript file. I’m also very fresh to JS so I could have made some basic syntax error. Am I using SendEvent wrong? Is there another way to send off strings to GameLift that I’ve completely neglected?

I’d appreciate whatever help you all could offer, thanks.

Hey there @Shadman_Quazi

I don’t see anything obvious wrong with the code you’ve provided. Based on above, when the server receives a message of OP_CODE_CUSTOM_OP1 it will send a message to all players in RED_TEAM_GROUP, and when it receives a message of OP_MESSAGE_COLOR, it will send a message to all connected players.

Some things to check / next steps:

  1. Verify client / server op codes match up, and the players you wish to receive the message have joined the group the message is targeted to.
  2. Add logging to the server script to debug your issue further and verify that its executing code in the expected path. GameLift Server Logs can be viewed via the AWS Console, GetGameSessionLogUrl API, or GetInstanceAccess API (See older forum post for more information: gamelift logs?)

Is there another way to send off strings to GameLift that I’ve completely neglected? =>

Besides sending messages to the server script via sendEvent(), you should be able to send messages to other players directly from the client via the SendMessage() method as well (specify the target group or player)
https://docs.aws.amazon.com/gamelift/latest/developerguide/realtime-sdk-csharp-ref-actions.html#realtime-sdk-csharp-ref-actions-sendmessage

So as it turns, I’m bad at reading my own code, I had set OP_CODE_CUSTOM_OP1 and OP_MESSAGE_COLOR to the same thing. changed them appropriately and everything is working as it should.

Thanks, @Nathan !