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"

Can't Save to Server from Client?

Hello!

I've run into quite the snag, I have set up a saving system that is supposed to be run on a server and -not- on the client. It starts at EventBeginPlay and loops. However, it is only running for the server owner and not for the client. Does anyone know how to fix this? Thank you.alt text

Product Version: UE 4.20
Tags:
help.png (128.6 kB)
more ▼

asked Aug 16 '18 at 02:05 PM in Blueprint Scripting

avatar image

Aggroed
15 4 2 6

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

6 answers: sort voted first

Since the issue has now completely changed and the primary issue that was the cause of this post was resolved, I'm going to list this post and answered and see if I can figure out loading. If not, I will make an post at a later point regarding the inability for a client to load a save from the server.

more ▼

answered Aug 21 '18 at 07:43 PM

avatar image

Aggroed
15 4 2 6

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

You told it to run only on the server because you only have an execution wire coming off the Authority pin and nothing coming out of the Remote pin (which is where it goes for remote clients connected tk the server)

more ▼

answered Aug 16 '18 at 06:07 PM

avatar image

mightyenigma
3.7k 18 19 20

avatar image Aggroed Aug 16 '18 at 06:30 PM

Thank you for replying!

Executing it from both/remote doesn't change it. It still only saves the server owner and not any of the clients. I've also tried making the initial event not replicated but running a RunOnServer variant for remote users, but this has not worked either

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

To make something happen on all machines you must make a Server RPC which then makes a Multicast RPC. Have you tried that?

Or you can just skip the server RPc and go straight to Multicast if the whole thing is always triggered from the server anyway.

What class has this code in it? it needs to be a connection-owning class such as Playercontroller in order to make a client to server RPC if that becomes necessary.

Everything you have here tells it to run the function on the server always - theres nothing telling it to run on any client.

more ▼

answered Aug 16 '18 at 06:45 PM

avatar image

mightyenigma
3.7k 18 19 20

avatar image Aggroed Aug 16 '18 at 07:22 PM

I may have explained poorly; I am trying to get it to -only- save on the server, I don't want to multicast because I don't want the client to save anything to themself, only save it to the server. But what is happening is only the server owner saves, and all others for whatever reason do not save.

I was originally doing it in the character BP but after reading your comment I moved it to the player controller. It still does not appear to be working, however. alt text

help2.png (181.5 kB)
(comments are locked)
10|2000 characters needed characters left

Oh! Sorry I misunderstood. Well I think character will work just as well as Playercontroller because the ownership chain leads to the same connection.

I dont know the answer but i have an idea. I think maybe the way it works is this: there is a difference between Authority and IsServer nodes. The former asks whether the owner of the connection is an ahthirity or remote role, but a remote client will still be a remote client player regardless of which machine is running the code. IsServer asks which version of the world the code is running on, rather than the role of the actor's owning connection (server's world or client's world)

So for this function if my theory is right, you could replace the Authority switch with an IsServer branch OR You could connect your SRV_GameSave directly to the MainGameInstance cast and maybe that will work.

I may be mistaken about how authority and remote works but its worth a try

more ▼

answered Aug 17 '18 at 01:59 AM

avatar image

mightyenigma
3.7k 18 19 20

avatar image Aggroed Aug 17 '18 at 02:23 PM

I've tried replacing the SwitchHasAuthority with an IsServer branch, unfortunately it has not changed the result. I have, however, found out a bit more about the issue. The client doesn't trigger the event until they pass the 'ReadyToGo' point (I had placed strings before this point and for whatever reason they don't trigger until then) after which point the game -does- start creating a save, but for the hosting user. So if a client has gotten past the 'ReadyToGo' branch, and the server tries to load a save even if they never generated one, they will instead load the client's save (technically the server's save since it uses their ID as the FileName, but the information being saved comes from the client). Similarly, if multiple clients are on one server they will all generate a single save with the ID/FileName of the server host.

Also to reference what mm tendies said, I have now made all the variables related replicated, which has not changed the outcome.

avatar image Aggroed Aug 18 '18 at 08:41 PM

I wanted to make a post with more detailed information in the hopes that it will shed some light on the issue.This good news is that after reading through your suggestions the main issue has been solved; the client can now save to the server. However, two new issues have arisen; Any client begining the save event generates a save event for the server, using the client's data, and the client is unable to ever load a save. The server can load a save, but if a client begins their own save event it over-writes the server's information.

alt text The Character on event begin play casts references of Player Controller and Player state, then on a loop refreshes and sends information to specific player controller.

alt text

In the Player Controller, the event being run from the character saves the character's variables to itself so they can be saved.

alt text

This is the improved (hopefully) save system based on your suggestions. It no longer creates a save on the client, AND it does make a save on the server which is great. However, for some reason it generates a save for the server regardless of wether or not the server has reached the 'Ready To Go?' state or not, and it fills in the information of the client playing. If there is more than one client as well as the server, it seems to randomly assign the save of one of the users to the server.

alt text

Lastly, and perhaps most importantly, the player can load their save from the HUD. If the server plays on their own without a client on the server, it works 100$ as intended; the server generates a save, and can then restart and load it. The client, however, is not able to load their save file even though it exists in the server's save game directory. Specifically, it determines that the save is Invalid from the is valid check.

imagea.png (173.2 kB)
imageb.png (127.2 kB)
imagec.png (150.1 kB)
imaged.png (231.7 kB)
(comments are locked)
10|2000 characters needed characters left

The world transform variable inside of your controller isn't set to replicate, which may be part of your issue, but if the event isn't firing at all, I'm not entirely sure what the solution could be

more ▼

answered Aug 17 '18 at 02:17 AM

avatar image

TheApplePieGod
26 2 1 3

avatar image Aggroed Aug 17 '18 at 02:23 PM

I have replicated all the variables, if you have further thoughts please see my above post I made in reference to mightyenigma. Thank you!

avatar image mightyenigma Aug 17 '18 at 07:54 PM

So have you confirmed that on the client machines, GameSave event fires at all?

avatar image Aggroed Aug 17 '18 at 11:14 PM

It -seems- to. For some reason it doesn't print strings until the 'Ready to Go' branch is true, even though they are before it. After that point it does print strings after the branch, and it is firing but creating only a save for the server owner.

avatar image mightyenigma Aug 18 '18 at 07:09 AM

What part of the code triggers the first GameSave? Maybe the problem is there.

avatar image Aggroed Aug 18 '18 at 12:32 PM

It starts on EventBeginPlay for the player controller. Essentially, it waits for a trigger that happens in the player character called 'Ready To Go', which happens at the end of the character's EventBeginPlay.

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

Since the issue has now completely changed and the primary issue that was the cause of this post was resolved, I'm going to list this post and answered and see if I can figure out loading. If not, I will make an post at a later point regarding the inability for a client to load a save from the server.

more ▼

answered Aug 21 '18 at 07:43 PM

avatar image

Aggroed
15 4 2 6

(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