I'm in the process of shifting my Unity game to Unreal Engine, and also shifting from using PlayFab + Photon (PUN) to using GameSparks, since GameSparks seem to be a more powerful tool after reading about it and testing it. So far so good.
What I'm trying to make a third person real time multiplayer. Now the problem is that I can't seem to find proper documentation for the unreal part for the real time multiplayer. I tried to see the Tetris Example, but I don't think it has what I need, or maybe it does but I can't seem to know what it is.
Can someone explain to me or guide me through the following:
After connecting to Gamesparks and logging in as 2 different users, and after matchmaking is complete, I start a session and I switch both clients to the game level (the game level consists of the normal "ThirdPersonExampleMap" that comes as a default with unreal engine's new third person project). When both clients join this level the third person character can't be controlled by the user. What I want to know is should I create a third person character manually for each player when the scene is loaded? and how can I make that character load on the other clients so they can see him, and how can I sync their position.
Thanks in advance!
This took me a while to figure out, but this link should help.
The way it works is you use the Game Mode to send your own player information to GameSparks. Then GS sends that data to the other clients. When they receive that data, they have their own Game Modes produce replicas of the other clients on your screen based on the data relayed from GS, which could include character class, position, rotation, velocity, etc.
The part I'm still working on is how to keep track of each player's data. I'm not sure how to link the data received from GS with the character on the map.
Hey Omar, Thank you for clearing some things up.
Everything seems good so far, but still missing the packet 0 that is not being received by the other clients, although it is being sent. Any idea why? I've got my blueprints attached in the above posts.
Regarding your comment on my actor tracking idea, I'll see what I can do to have it update every time someone joins or leaves the session.
Regarding your possess pawn issue, does the camera correctly follow/jump to the new actor and your controls simply aren't working? Or the camera isn't working either?
Regarding the GameMode on the server, that is just referring to Unreal networking. Because there is only one player in Unreal's eyes, your device IS the server. So because we are using GS for networking, the fact that the GameMode is only on the server is irrelevant for most situations.
Regarding the elusive Packet 0, I'm not sure what could be causing it, since everything looks good to me. Omar might have some ideas, but you might just need to start moving things around to see how it changes.
Hi guys, you shouldn't use packet with an OpCode 0, it does not work. Similar to having anything with the index 0 in the data object of a packet.
Anything from 1 up works.
I am aware that Unreal's server GameMode is only relevant to the Server and clients cant access it. For the base SDK (Normal requests) it's best practise to first connect in the clients GameMode (Main menu before joining a session) this will ensure that they are connected and able to make calls. For the real time SDK, it was never meant to work side by side with Unreal's networking layer. Every player will have their own game, they are the server authority of that game and the packets ensure replication. This is the intended use of the real-time SDK. This is not the only practical use, but this how we design it to be as it is agnostic of Unity, Unreal and any future IDEs SDKs we plug it into.
Hope this helps,
Hey Omar, thank you for pointing out about the OpCode 0.
I've changed the send spawn OpCode to 2, but still isn't being received on the other clients. This is giving me a hard time starting my project. Also taking control of the player is not working (possessing).
Hey Chris, I was able to create a scenario where all players' positions are synced while lerping their movement. But I have noticed that it will require a lot of work to make my game since it depends a lot on quick actions and physics and so on.
I made a thread about comparing Unreal's networking and GameSparks' Realtime SDK to check which is better/easier for my game:
FINALLY! The spawn packet was received! All I had to do was add an "Create GS RT Data" and attach it to the Send's Data variable. It seems it needs an empty Data to be sent, can't leave it empty.
Now I just have to figure out how to take control of each client's player so I check if the location packets are sent when the character moves so I duplicate them on the other clients.
Figured out that the 100 OpCode is sent from the real time script.
Still can't figure out from where the "Id" variable came from.
Now I've attached a "Print String" to the custom event "OnDataDelegate" so I can see the incoming packets, but it seems I'm not getting any. The other 3 custom events (on player connected/disconnected, and the onready) are working so I don't think I have setup anything wrong here, so the OnDataDelegate should be working.
I've attached 2 pictures showing the delegates part. Did I set anything wrong? Or should they work normally?
The Id variable is generated from GS when the MatchmakingRequest is sent. That part you can see if you test it in the test harness. You can obtain the Id's like this (also attached): add a GSMatchmakingNode, break the resulting Match Details Response, from there add a ForEachLoop that takes in the Opponents array, which produces GSplayer structs which you can break to get the Id of the opponents.
You have the "receive" end set up properly. Now you just have to actually "send" the data from within your Blueprint (attached). Picture it like the game Battleship. You each have your own game board, and you're telling the other person where your next move is. You have to send the data to them, and they have to receive it. After it is received they have to interpret it in a way that results in a perfect replica of your character as you see it.
I'm looking into making use of the Id variable. I didn't realize the Tetris example utilized it. I'll look into that tonight.
Keep the questions coming. You're helping me understand this better by trying to explain it, and this should help other people that have similar questions since UE4+GS is relatively new still.
It looks like the Id in the Tetris example is a different variable than what I referred to. The Tetris example has its own custom variable called Id which is simply an integer that represents a shape. Each shape (I, L, and T) has a different integer so that integer can be passed to the other clients via the Send node. When the clients receive the data, the Blueprints should then recreate the shape based on the corresponding integer.
Hey Chris, sorry for the late reply. I agree that this post will be helping us better understand the gamesparks real time using unreal.
I was able to fix receiving the OpCode 100 from the cloud, turned out I forgot to add the "contains" function. Now the clients are receiving the OpCode 100 and the game is starting.
The new problem is that when the game starts, I'm sending an OpCode 0 so the clients know that I spawned a new player. But this packet doesn't seem to get to the clients. While the OpCode 1 is for sending the location of the client, I'm able to receive it on the other clients. Seems kind of weird I can't figure the problem out.
I've attached the sending part of my blueprint and reattached the new receiving part(added a print string for received OpCodes, and attached the Data variable to the Spawn Player and Set Network Player Location). Both strings "Spawn Sent" and "Location Sent" are being printed, but only the Location is being received.