x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Detect game quitting in Blueprints

I need to run a piece of code when a player exits the game through means other than the exit button, specifically I need to run a php code that updates the online status of a player which is very important but how exactly do i know when a player exits the game? For instance when the player kills the game through task manager or simply shuts down his pc or any other way of losing connection really. I found this post https://answers.unrealengine.com/questions/127897/event-on-close.html but it doesn't help much with blueprints since there isn't a game engine class...help?

Product Version: UE 4.20
Tags:
more ▼

asked Aug 27 '18 at 03:48 AM in Blueprint Scripting

avatar image

ukiW
26 1 2 7

(comments are locked)
10|2000 characters needed characters left

3 answers: sort voted first

if the player kills the game then nothing is going to get executed, it is a simple as that

more ▼

answered Aug 27 '18 at 03:56 AM

avatar image

Nico_Pucho_27
73 4 11

avatar image ukiW Aug 27 '18 at 04:32 AM

Then how can I know if a player loses connection? I've seen some ping-pong type solutions that go back and forth from client to server every second but I'm not really sure how to create it using blueprints.

avatar image Shadowriver Aug 28 '18 at 04:32 AM

If you run unreal server then oyu can detect disconnection in game mode events. If you try via HTTP the you sadly limited the same as websites, as thats nature of HTTP. \You need to use heart beating (Sending "im here" massages) and turn use offline when it does not responce over specific heartbeat time. You might consider using diffrent protocols too.

There possibiloity to detect closure in C++, but even so what about crashes and power downs? You should not relay on user exit messages, insted on connection status as you figured that yourself

avatar image HarryHighDef Aug 28 '18 at 08:44 AM

What you could do is use the client side to check the game quit event and see what closed it. If it was the in game menus or a force quit. Then you could send a final package to the server detailing the quit status.

avatar image dZh0 Aug 28 '18 at 01:36 PM

if the player kills the game then nothing is going to get executed, it is a simple as that

True! So true. In real life you usually check from the server if the client is "live" periodically to close the connection of "killed" clients. This should be already implemented in UE4 networking system.

avatar image ukiW Aug 29 '18 at 01:44 AM

Hey, can you please explain how to do this? It would be much appreciated

(comments are locked)
10|2000 characters needed characters left

There's a virtual method in the AGameMode class called Logout, which is called every time an AController leaves the game. You can override it in your own GameMode classes, check if the AController is an APlayerController (Logout is also called when AIControllers are destroyed) and then have your UE4 server make the HTTP call to your PHP server.

If you're using Blueprints, the event you want is called OnLogout and is only called for human players.

more ▼

answered Aug 29 '18 at 02:53 AM

avatar image

Manoel.Neto
81 1 3 2

avatar image ukiW Aug 29 '18 at 03:19 AM

Hey, thanks for replying. I've been messing with this for some time and apparently, it doesn't work as intended when played in editor since no php requests have been sent post logout. I'll be trying this once i compile my server and see how it works in that environment and letting everyone here know if it works.

Also while we're at it, since I've been looking at alternatives, do you know if there is a way to use the ping-pong type communication between server and client every so often as a check if the player is online in blueprints? I've come across a solution in C++ that uses sockets but haven't had much luck in blueprints. Do you perhaps know a way to do this?

(comments are locked)
10|2000 characters needed characters left

I would do it using heartbeat messages like ShadowRiver suggested. It's the only foolproof way. You can get a faster response by adding logout event handling to it, but the only way to really detect for example, that the user experienced a sudden power outage or their toddler poured soda on the computer, is to notice that say, 3 heartbeat messages in a row did not come in when expected. once you get another one you flip it back to "online" status.

more ▼

answered Dec 06 '18 at 06:30 PM

avatar image

mightyenigma
3.4k 16 17 12

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question