#multiplayer
1 messages · Page 471 of 1
GetGameInstance will only ever get the game instance of on the local machine running that code because thats the only game instance that exists there
I think I'm missing something important, the dedicated server (from ue wiki) requires to pass a map/level name/path to either the name of the server executable or to the properties of the executable, which leads me to believe that what the server hosts is a single level is that right?
i havent had to do that
if youre trying to make it start on a specific level you can just use servertravel or open
Should you store an array of controllers in the GameMode, or is it more wise to just iterate using the FConstControllerIterator instead whenever you need something to happen on all connected players?
so if I change level the dedicated server will be the same for both levels?
@grizzled stirrup GameState maintains an array of all the PlayerStates, and if you're on the server you can get the controller from a PlayerState by getting the owner of the playerstate
Very true! I for some reason had it in my head that I needed to store the controllers in the GM
However ShooterGame usually does iterate over all controllers instead of get the PS array from the GS
Are there any benefits to either approach or both are valid as usual?
ShooterGame doesn't store them though, just iterates
Which is much more smart than my Array approach
oh yeah GetPlayerControllerIterator is good to use also, since the world maintains a list of the player controllers, so it's pretty cheap to use
but just remember that only works on server
since on clients they only have the player controllers for the local clients
Yeah that's fine, I need it to just loop over all controllers for cases like the round ending or to activate all players and AI
Thanks for the help!
In cases where I need something to happen on the player, I call a client RPC on any PC's
Like if some UI has to pop up saying ROUND LOST
that seems like a more complicated version of multicast on game state
Just following a similar pattern as ShooterGame
If theres 20 bots and 2 players it seems just as efficient
As the bots don't need to ever get the multicast call
For UI stuff
Lol not that they would (waste bandwidth) being on the server
But still
Oh interesting
using GameState for things that change the state of the game (like the round is over or whatever) is a more correct way to do stuff like that, sometimes ShooterGame really cuts corners
I thought only the PlayerState was optional but it makes sense, no need for them to have the GS
The GameMode should always actually end the round though right, and be counting down the world time?
there's basically only one GameState per process. So the server has one, and each client has one
Then it can tell the GameState- hey the round is over, notify the clients
yeah
Ok thanks, I might try and move over that logic
sometimes ShooterGame does things in a quick way, they try to balance ease of understanding with it works
With it's correct
I see, will definitely have to have another look
more importantly, shootergame was made like 6 years ago
a lot of the ways they do things are just outdated
They do everything like showing scoreboard in the GM and just update time really in the GS
like using slate ui at all
Ok got to keep that in mind
Yeah haha
That's the most outdated part of SG
I am using it to learn UE4 C++ though so it's tough to know what's outdated and what isn't with very few other complete examples
Just game flow in general
So in the case where you are iterating over all controllers n the GM to deactivate AI at the end of a round you'd still instead call a multicast RPC on the GameState to deliver the end of round status?
Instead of a client RPC since you are already iterating over all controllers anyway?
I've moved my Game timer from GameMode to GameState and back like 3 times, opinions are quite conflicting haha. I've settled on the actual timer going off in the GM and it telling the GS what the current time is
I'd keep track of the ais separately
I'm trying to treat them all as players
Regardless of AI or real
So same pawn and the only difference being the controller
So would like any events like end of round controller iterations to be as similar as possible other than in obvious cases like UI for client or activating / deactivating AI
so from the test I just did it seems that indeed the dedicated server only hosts a single level, because the game instance doesn't keep state...
so how do I create a server side variable (i need it to be secret) and pass it across levels?
in the game instance
what do you mean by secret
anything on the server that isn't replicated is "secret"
but changing/opening to another level that isn't the one hosted by the dedicated server resets the game instance
or at least that's what i see in my test
no it doesn't
what do you mean opening another level that isnt hosted by the dedicated server
the server should run servertravel to make clients move with it
if you open another level as a client then of course the server's game instance will change because the client opened up its own level and disconnected from the server
so it becomes its own server
try servertravel testlevel
also
nothing should come after that command
because it loads a new level
still not werking
what would indicate "working"
testing dedicated server stuff doesnt work in editor btw
so I need to build in order to actually travel?
yeah
especially if youre testing stuff with the server's game isntance
you need to package the game and build the server
as far as i know theres no shortcut to that
okay ill test with a packaged version
what I was refering to earlier is that, since Im changing level I will hold a non-replicated variable in game instance in order to pass it across levels, but since there is only one game instance on the server, and I need one of this non-replicated variable that is set at login per player I don't know how to approach that
idk if this would work but maybe have an array of maps in the server game instance where you somehow get the index/id of the player/client and assign it as a key, and then a custom map value
what is the best way to check that?
this is first time that i see this
you are right, it's in Character
those are sent from the autonomous proxies to the server as part of the normal movement flow
how do i get a bool on an AI animation blueprint to replicate to everybody else? It's only being set on the server so clients arent seeing the updated poses
tried doing RPC's to no success
nvm i got it. brain fart. dont replicate variabled in animbps
@thin stratus sorry for the tag, you mentioned the amazing GM OptionsString property to pass rule changes in to the GM without having to store them in the GI or similar, I'm just have a slight bit of trouble understanding the difference between the key and DefaultValue in the case of setting an int.
Would the correct workflow to pass in a different MaxPlayers value be like so? In the console type open MyMapName?MaxPlayers?MaxPlayers=4 and then at StartPlay() in the GM have this line: MaxPlayers = UGameplayStatics::GetIntOption(OptionsString, "MaxPlayers", MaxPlayers);?
Am I correct in using MaxPlayers as the "DefaultValue" argument in GetIntOption?
It seems to work when I test it so far....
I'm not sure how to convert a float option though, as it seems that only strings and ints have funtions in UGameplayStatics
open MyMapName?MaxPlayers=4
You don't need UGameplayStatics::GetIntOption(OptionsString, "MaxPlayers", MaxPlayers);
MaxPlayers is a used key word and already handled
So it's set automatically with no calls at all?
It is handled in the engine
Wow that's incredible!
So I guess that means it works for floats etc automatically
Thank you so much!
This is a gamechanger
Only for the ones that are handled by ue4
Your custom key words have to be handled by you
As in any regular properties that you define in your GM (time / score etc.) will be handled automatically?
Oh that's actually a custom one in my case
Defines how many bots are spawnd
So to handle yourself, what is the correct approach? Using that UGameplayStatics call?
Yes
And if so, how do you get floats back if it can only return strings / int32s?
You could pass the float as a string
And then use the String library to convert it to a float
Or you just make sure that you always only pass ints :P
I guess most things are whole numbers even if they are floats like Health
bRequireFull = UGameplayStatics::HasOption(Options, OPTION_REQUIREFULL) || bRequireFull;
bRequireReady = UGameplayStatics::HasOption(Options, OPTION_REQUIREWARMUP) || bRequireReady;
if (UGameplayStatics::HasOption(Options, OPTION_MINPLAYERSTOSTART))
{
MinNumPlayersToStartMatch = UGameplayStatics::GetIntOption(Options, OPTION_MINPLAYERSTOSTART, MinNumPlayersToStartMatch);
}
bAllowMapVote = UGameplayStatics::HasOption(Options, OPTION_MAPVOTE) || bAllowMapVote;
if (UGameplayStatics::HasOption(Options, OPTION_OVERTIME))
{
Overtime = UGameplayStatics::GetIntOption(Options, OPTION_OVERTIME, Overtime);
}
bTeamDamageEnabled = UGameplayStatics::HasOption(Options, OPTION_TEAMDAMAGE) || bTeamDamageEnabled;
bBalanceTeams = UGameplayStatics::HasOption(Options, OPTION_AUTOBALANCE) || bBalanceTeams;
bCanRespawnByHand = UGameplayStatics::HasOption(Options, OPTION_RESPAWNBYHAND) || bCanRespawnByHand;
bWaitBeforeRespawn = UGameplayStatics::HasOption(Options, OPTION_RESPAWNWAITTIME) || bWaitBeforeRespawn;
if (bWaitBeforeRespawn)
{
RespawnWaitTime = UGameplayStatics::GetIntOption(Options, OPTION_RESPAWNWAITTIME, RespawnWaitTime);
}
bForceRespawn = UGameplayStatics::HasOption(Options, OPTION_FORCERESPAWNTIME) || bForceRespawn;
if (bForceRespawn)
{
ForceRespawnTime = UGameplayStatics::GetIntOption(Options, OPTION_FORCERESPAWNTIME, ForceRespawnTime);
}
bForceWarmup = UGameplayStatics::HasOption(Options, OPTION_FORCEWARMUP) || bForceWarmup;
Few custom examples
Ahhh thank you so much
Your snippet from last time on making your custom OptionsString was v helpful
This is the missing step!
Thank you
I have mine in StartPlay() but I'll probably move it to InitGame then
This is a super useful option, makes custom games so easy 😃
Yop, requires some time to setup but then it works
In the case of the capital letter properties, what are those?
OPTIONS_MINPLAYERSTOSTART
#define OPTION_MATCHTIME FString("MatchTime")
#define OPTION_NUMTEAMS FString("NumTeams")
#define OPTION_BOTCOUNT FString("FillWithBots")
#define OPTION_BOTDIFFICULTY FString("BotDifficultyLevel")
#define OPTION_REQUIREFULL FString("ReqFull")
#define OPTION_REQUIREWARMUP FString("ReqWarmup")
[...]
#define OPTION_AUTOBALANCE FString("AutoBalance")
#define OPTION_RESPAWNBYHAND FString("RespawnByHand")
#define OPTION_RESPAWNWAITTIME FString("RespawnWait")
#define OPTION_FORCERESPAWNTIME FString("ForceRespawn")
#define OPTION_FORCEWARMUP FString("ForceWarmup")
#define OPTION_MAPCYCLE FString("MapCycle")
Sits in our main header that holds or sorts of structs and types
that and you don't have typos :P
could also make them FNames, not sure
this works for us ¯_(ツ)_/¯
Either way it's important to use the FString("thing") or FName("thing") right?
I just used "thing" and it worked but I'm sure it's not the most correct way of doing it
a #define replaces whatever OPTION_XYSDAASD you have with whatever you write after that
#define SEMICOLON ;
tada
Ah ok makes sense! Thanks
Finally, to set a particular key in Options, how do you go about it?
If you weren't going to go the route of the console command opening as I have
?MaxPlayers=4
I thought you have the struct example?
"Your snippet from last time on making your custom OptionsString was v helpful"
It's always ?Key=Value or ?Key
Literally just ``Options += "?" + "MaxPlayers"= "NewMaxPlayers"
Sorry
I will go back and find it, I had though it was more for creating the full OptionsString
As in combining the different possible keys
My struct has a function that just formats all the parameters into a string
I'll try and have a proper look to understand now, apologies!
Ah great yeah that makes sense! Much less scary than originally thought
I'll probably have a nice UI that can set a few params and on hitting "Start Game" it goes through all of them and makes the string nice
Thanks again!
e.g. if (Options.bWaitBeforeRespawnEnabled) OptionsString += "?" + OPTION_RESPAWNWAITTIME + "=" + FString::FromInt(Options.RespawnWaitTime);
Ahh even better
So I can check if it's not default
and if not, add to the string
Thank you for these examples
depends on your game settings of course
Really helpful
Enjoy!
OptionsString += FString::Printf(TEXT("?%s=%d"), OPTION_RESPAWNWAITTIME, Options.RespawnWaitTime);would be cleaner no?
Hi! probably anyone can suggest me how to rotate standard character by actor with rot mov component in multiplayer without "actor like replication", I want to use default out of the box Character network functionality.
Character is staying on the rotating platform for example
Is there a way where I can gracefully shutdown my server
coz GIsRequestingExit = true; this works but its not graceful
FGenericPlatformMisc::RequestExit()
However it does the same thing, and that is the expected way to shut things down.
ConsoleCommand("quit") is a classic too
Nice ! let me try
ConsoleCommand("quit") Works better 👍
is player state good enough for server-side non-replicated variables?
why would you use playerstate for that?
well i need this variable to relate to the player somehow
controller is a more natural fit
ill do it in pc then, why is it better there?
because its not the PlayerStates purpose to hold non replicated server only variables
its the opposite, for the most part
so you put stuff where it belongs
makes it easier to remember/find where it is few months down the line
the only reason to put it in PS is if you really need it to survive a player disconnecting
makes sense thx
Regarding showing a widget on clients at key moments of a match such as at the end of a round, ShooterGame does it by looping over all player controllers and calling a Client RPC in the GameMode, but some here suggested to move this to the GameState instead. If I was to say have a replicated MatchState struct that would trigger an OnRep event when changed (such as at the end of the round), how do I go about calling the UI event only on the current player? Looping over all player controllers and checking if is local controller and calling it there?
OnRep should be enough for that
if the newly replicated value indicates that the game is over, show the widget
Yeah the tricky part is calling it only on the local human player as the gamestate OnRep doesn't have the concept of owning controller etc.
So I'd probably just do what I did in the GM and loop over all PlayerControllers and check if it's the local one, if so call the UI function?
I guess for a local client, he will always be the first controller, so I don't need to iterate actually
I can just GetPlayerController(0) and call it
just dont do it for dedicated server
Looking for a dev who can help us set up multiplayer for our FPS game
Or at least give us some pointers
Hello, beginner question here, anyone got time to help me? 😃
Post your question mate, someone will get to you eventually. No point asking for help, just ask the question you need help with.
Alright sec
So the most important thing of the blueprint is there i think, when my melee character makes a hit , it is a sphere trace that does damage to the enemy, and prints the damage
but when i am playing on the client side it does no damage, and ofcourse the print string says 0 in damage
So i would love some guidance in this, thanks regards
You have to resolve damage on the server, and then the server can notify the client when there’s damage so it can show it on the UI
You don’t want to do damage calculations on the client usually
Because the server is authority
Did you somehow write a huge amount of data and overflowed the size?
Yes, im aware that the server does most of the stuff, can you help me where to but the stuff so the client can see it ?
i need a custom event with an authority switch ?
I just don't know when to start call it ;>
but it's not overflowed, it says there's still 7KB remaining
it just died because it tried to write -1 bytes for some reason
oh wait.
alright this is one confusing constructor but here it is adding the -1
I guess I'm sending too many reliable thingies
@lofty ravine the simplest way is you make a Server reliable function, and when the client wants to attack, you call that Server function, then everything from the trace onwards is done on the server
im calling an event defined in a widget blueprint from a client rpc defined inside the player controller blueprint, but it isn't being called
you sure the client RPC is being called? and is the owner of the widget set to that player controller?
im sorry for being slow @copper mango , but we got this working on archer , for both server and client
And it all starts from oncomponenthit
sphere
And we don't even need authorty switches or anything
But now on the warrior when the event starts on a keypress, it doesn't work
oh, so if you're doing it off of OnComponentHit, that means it's running both on server and client
however, if you're doing it off of a key press, that's only running on the client, since the server won't know about the key press
but then the client can't actually resolve the damage, which is why it doesn't happen
Ahhh, okey, an off question, how do i know what event runs on what?
the client rpc is indeed being called from client
in Blueprint, honestly I'm not really sure if there's an easy way to know
So i should just add an sphere on the warriors sword and start he event on an oncomponenthit and it should be solved ?
if you did that then the component hit or overlap would trigger on both server and client, yes
does get all widgets from class only show you the widgets that the player controller "owns"?
I honestly don't know about those blueprint functions, I just nativized most of my user widget updates
i found that the array im setting in the server isn't replicating to the client
the widget is created on a client rpc yes
so what's the array for?
a json array, im setting it in a server rpc, and im trying to use it on the client rpc but the array is empty
like you passed it as a parameter to the RPC?
nope, im just getting a reference to it
how do you guarantee that the JSON array is replicated before the RPC comes in?
thats actually a really good point xD
one thing you could do is send the JSON array in a client RPC when you set it, rather than replicating it separately as a variable
because it's guaranteed that if you call RPC A and then RPC B on the same object, A will execute before B
at least if they're reliable
assuming that array is changing infrequently at least, that shouldn't be a performance issue
hmm the array is sent with the correct number of items but the jsons are empty
wtf
how is it possible for UCharacterMovement::ReplicateMoveToServer() to run for a character which fails this: check(!HasAuthority() && IsLocallyControlled());
@harsh lintel might be that JSON struct/whatever doesn’t replicate. There are some rules about what TArrays will work in an RPC
Basically everything needs to be a UPROPERTY or you have to override serialize I think
thanks, Ill just get the data as proper types and send it to the rpc
Whats the best way to setup random character mesh spawn....i randomly select the character when the game starts in the game instance and then when the player joins the server he then spawns that randomly selected character but the problem is every ones character is the same :/
any reason why i see the same characters for everyone instead of the randomly generated characters for each client?
Well game instance exists per process. So if the server game instance selects a random character, that would be used for all clients, since the server is responsible for spawning the pawns in the game mode
You can override SpawnDefaultPawnFor in the game mode, though I dunno about blueprints
you should definitely not use GI for choosing random characters, unless you really want the random persisting thru multiple level changes
that is GameMode's job
overriding HandleStartingNewPlayer (possibly in combination with override ChoosePlayerStart)
is the easiest way to make custom spawn logic from BP
When using FFastArraySerializer, what is the equivalent of OnRep (or should I just use OnRep as I am currently doing)?
I see the PostReplicatedChange/Add stuff, but I'm not entirely sure if that's what I want.
Because, if I use PostReplicatedChange/Add, wouldn't it be hard to get a reference to the actor with the FFastArray array?
since you're creating the serializer in your class, you just register the actor with it
or whatever is using it.
in your custom serializer
and then you use the postreplicatedxxx stuff
as you said.
eg:
{
//a change came through (dirty item) update displayname and stack count.
if (InArraySerializer.Owner)
{
InArraySerializer.Owner->OnReplicatedItemChanged(*this);
}
}```
Ooooh, that makes a lot of sense. Thanks so much!
@white mason c) timing d) incomplete implementation . for instance it may work on server because all characters are always relevant, so your code works as expected, but on client they are streaming in and out, and it matters who does streaming in first (either the weapon or the character). try applying some timers/delays and make sure the character will configure the weapon and iks always, properly.
@rotund sapphire If i spawn weapon some time after beginplay, everything works fine so what's the problem?
as long as weapon has SetOwner called on server when its spawned
and your OwnerNoSee/OnlyOwnerSee boxes are checked properly
(assuming here weapon itself is replicated)
everything works fine
Hello does anybody have experience with the replay system thats able to help me out with actually renaming a recorded replay? I found the wiki tutorial on replays which brute forces it by modifying the save file but I also found the INetworkReplayStreaming interface which has a function for renaming replays... and I cant seem to find out where to access it
Other than actually creating a replay streamer...
does it generally make sense for players to be the owners of projectiles they fired?
Ah ok I found out how to access it, using the DemoNetDriver on world context objects has a shared ptr to the replay streamer so I can call those functions
@winged badger i suspect the issue at @white mason is that the character will replicate first, then the weapon later, so the character cannot setup the weapon iks and the code fails somewhere down the line. Znany, just make some logs in these steps and make sure the sequence of events are in correct order, all is running. I think you will find the circumstances are invalid, and so the ik cannot be setup without the weapon being rpesent and available at the right moment. Hence, timing issue (or call it race condition maybe)
unless he really went out of his way to mess up the network, weapons spawned in same frame as the Character will come in second, as Actors take a back seat to Pawns in priority
so weapon will have a valid pointer to Owner by the time it calls BeginPlay on client
it's not guaranteed though
There is no guaranteed order of replication of individual actors, even if you set the ownership and priority it makes no difference, and the order will be pretty much random. With 4.20 that's what i have found at least.
the bunch with the character could always be dropped
...
basically, that can never happen consistently
the packet getting dropped
and never in PIE unless you configure it to do it intentially
I dont think it is getting lost, but drop, and the weapon may stream in a second later after the character - or the other way around.
not in PIE, which that almost certainly is, Robert
I've added defered methods that are waiting for the weapons to arrive, then i execute the operations on them.
i spawn my weapons between my SpawnActorDeferred and FinishSpawning call for the character
it has never, once, failed
or arrived out of order
It may fail once the character is coming from afar. Also don't forget to check your game with network latency, and other noisy circumstances.
like testing over internet with a failing 7 year old wireless card?
i do that all the time
Not what i mean. Network latency, packet order errors, randomize latency and so on. You can try packet drop too if you want to torture the code an try all circumstances.
But anyways, i'm happy it works out for you. For many it does not, and the order of replicated actors are never guaranteed, makes any code suspectible of invalid expectations to fail eventually. Both in PIE and cooked game the circumstances are always in motion in this matter.
i have growing, altho not yet 100% confidence that this can't fail
my entire object graph is ready before clients call BeginPlay
game has been thru various network tests for over a year now, not one incident
with spawning weapons/characters
in any case, in Znany's scenario, if the mesh has the correct Owner, and its replicated by default
You may be spawning the weapon on client side, manually. But if you spawn it on server, then replication will make fun of us.
it will adjust its visibility OnRep
how'd you manage that
There maybe is more to your solution which sounds intriguing actually.
I always get characters before player/game states
i spawn nothing except target markers and such client side
@fleet raven assuming no packet gets lost/stuck, actors will arrive in order of NetPriority
Pawn and Characters have 3
Actors 1
So that makes the character arrive before weapon, which is the problem, because character will try to run weapon setup without the weapon actor available at that frame.
Not sure how'd you throttling the character beginplay to wait for the weapon actor to arrive, it may take a second actually.
is it actually necessary to receive characters and weapons in the same frame tho
that assumes i have to do more then bind delegates inside OnRep_Owner
well I guess my order being wrong all the time is far better than it not doing that in the long run
because otherwise I wouldn't take care of it and it would randomly crash clients on bad connections
i don't really care if Character BeginPlay runs before the weapon arrives
it just needs the controller already there to work
same as weapons just need a valid poitner in onrep_owner to work
one rule i didn't break, never put yourself in situation where a replicated actor has more then 1 actor its dependant upon already there client side to work
I'm sure it's avoidable tho the solution might gets too troublesome to maintain.
except for if dependancy is loaded from a package, then you just don't care
Timing issue however is something you can treat, it just messy a bit.
does anyone know of any more detailed guides/information on remote dedicated server networking? Im at the point in the known wiki tutorial on dedicated servers, where I have just typed in my public IP to the travel map BP, but other computers are not able to successfully connect to the server and travel to the playable map. Ive seen this asked on the answerhub and forums but no real solid answers.
Open a port on your router so outsiders can connect to your locally run server
well i did port foward on 7777. But im running the server on 1 computer in my house and trying to play on another. Does this not work if the computers are on the same network?
I guess i need to try and connect from another network to really know its not working 😑
If you're using null oss then it should work. Since you're running it locally you can connect to your server using the lan ip, outsiders must use your external ip however
You should be able to connect to your own server using the external ip too
Also check on firewall settings and make sure it is not limiting the process to interact with the internet in any way
There also is one more awkward circumstance when your network is behind multiple NAT, in which case only steam will work. Alternatively you can just upload your server to the cloud and get it shared that way - it's the preferred way actually
yeah i want to do that eventually but im just testing it right now
i just want to see a client connect
thats all i need
then just connect your own client to your local ip of your server and it should work - if everything is good with your cooked game and server
logs can tell you if something is broken and the client gets dropped or something
well problem is, I have my public IP baked into the entry level bp. Begin Play -> Open Level (public IP), and the game is packaged.
Ive seen it work already using my local ip
That's not a problem :) The problem is that it is not connecting for others, but like i said it is possible your ISP is using additional layers of NAT so you wont be able to host p2p games for others. Just upload your server to the cloud it should work. On amazon you can get tiny instances for free for a year, that's a good place to test things i guess.
Ok ill give it a try. Thanks for the advice
Is it possible (without using a custom engine build) to load a random map that isn't the GameDefaultMap when disconnected from a server?
bind to the server error delegate and call UGameMapsSettings::SetGameDefaultMap(MapString);?
@copper mango i tried what you metioned but no luck
the random character selected
so I'm trying to get my shooting working so clients can actually aim, but I don't know how to have the server see that a client is aiming X degrees up/down, so when I shoot from a client the line trace just goes directly forward out of the client even when aiming up or down, also the server player can shoot in any direction and it works as intended
this is my weapon BP (yes I know the line trace shouldn't be in there please don't murder me for improper organization):
https://i.imgur.com/m5qifJo.png
also when I shoot, the client sees the correct bullet impact location with the added straight ahead one, but the server only sees the straight ahead one
here's an example of in game, the client is on the right the server is on the left:
https://i.imgur.com/uugY836.jpg
I believe if you use GetPlayerViewPoint on the player controller, that is replicated client to server
I couldn't find that function
ah let me see if that's it
it worked! thank you
stupid though that it wouldn't work with the camera's rotation
reason is just the camera isn't replicated at all, but that separate actor view thing is
because like the server doesn't really need to know about almost anything camera-related, so it'd be a waste of bandwidth to replicate it
i have a menu ingame to allow admins to configure server settings which are all part of one struct
it keeps track of settings that were changed so only those need to be sent instead of all of the settings
is there a way to send only specific data in a struct in an RPC to reduce the size of the data thats sent to the server
or do i need to have a separate RPC for each setting
using cpp
yeah then its up to you how you handle the rpc
i wouldnt have a rpc for each value, i would just be sending a struct, its not like your sending the rpcs all the time
so why be concerned?
i havent checked the actual size but its decently large
not that its anything significant
more so just wondering if i can optimize sending it
Hey all! Having an issues with a shield spawning in 2 different locations. Here is the spawn code:
Currently im getting one spawning on the arm in the correct location and another spawning way off to the size but rotating with the player pawn when i move. I honestly get the feeling im messing up something fundamental as even the projectile im throwing around had issues with hitting itself(or a duplicate)
is the actor set to replicate? spawning it in a multicast would mean the clients are spawning one as well as spawning the server's
yes its set to replicate, does doing that along with the multicast cause the duplication?
yes because replicated actors spawned serverside will spawn for clients
so they're spawning the one that's being attached locally and then getting the server's actor that isn't attaching to anything
ah that makes all the sense
i was thinking of the replication setting as a requirement for it to be multicasted. Thanks for the clarification!
the actor that spawnactor is being called on needs to be replicated in order to call RPCs
but spawning actors through multicast is bad compared to just having the server spawn it
try that and then call the attach on beginplay
that comes with the benefit of newly joining clients spawning the actor and attaching it too
Do you mean the actor in which the SpawnActor resides or the class type specified in SpawnActor?
the actor spawning the actor needs to replicate for an rpc to work
makes sense
but instead just replicate the shield actor and spawn it on server only
that will spawn it for everyone
Thanks again for the clarification, it really helps! Right now everything is working as intended so im going to go mess some more stuff up!
I need a little help with this, I'm trying to get a lock-on system that functions regardless of which player you are, but currently it only locks on to player 2's spawn point. doesn't follow them even if they move, not to mention this is also true for player 2.
Any ideas?
@elfin veldt Get Player Pawn doesn't get the player from the PlayerState...it gets the one assigned to the player controller index you pass in
if you're wanting the pawn associated with a PlayerState, I think in Blueprint you just access the PawnPrivate variable off of the player state
@copper mango what is Pawn Private exactly? nothing seems to have changed though likely because I'm dense.
it's the pawn associated with that playerstate
how would I get the pawn for both players?
how do you want your lock on to work? like you press a button then what happens?
end goal is pretty much make the camera look at the other player.
somehow It's focused on the world origin at the moment
so no matter where I move player 1 or player two, they both look there.
what's the intent of your SetPlayerPawn function?
like right now, for each player state you're setting the associated pawn's target location as its own location
I don't think what's what you want
I'm sure it isn't, I'm just unsure of how to actually do it.
so to get Player A to constantly look at Player B, you want to just save Player B and then in tick or whatever you need to update your facing to look at the new Player B position
you have to update it every frame since the player might move
but how do I decide player a and player b
well your InputAction Lock On or whatever is in your controller, yeah? so inside the controller you can use Get Pawn to get the Pawn associated with that player, and that's player A
for player B it depends on how you want to figure that out, like if you know it's only ever two players, then you know the player that's not player A is the one you want...if there's more than that then you'll have to decide however you want to
but I honestly don't really do blueprint stuff at all, so I couldn't tell you like which specific nodes and all that to use
you might have better luck with the folks in #blueprint
All, I'm experiencing something unexpected. I've got a player who controls a character (military). At a given point, this player possesses a Drone, so unpossessing the character.
If the possess happens when the character is moving, GetVelocity in the character's animBP returns the speed that the character had (so > 0) despite the fact that the character is not moving, so this happens:
https://gyazo.com/b9010bcdb689f12250e3da5177177ae4
What you see printed there comes from the animBP:
but as you can see the character is not moving.
In MP this is pretty clear:
https://www.youtube.com/watch?v=R58rObo1VT4
How in CPP replicate override void from interface?
virtual void InteractWithObject_Implementation() override;``` I need to create 2 functions in interface like this? (above)
```void InteractWithObject();
bool InteractWithObject_Validate();```
Not sure unreal will like mixing interfaces and rpcs
And its a dodgy idea to start with, as implementing an unterface doesnt mean the actor has a data channel to sent the rpc through
Shiet, I need use rpc to interact with objects like lamps or gate switch
when you interat
interact
simply in your Interact implementation send a RPC
for that object
as long as the object is net name stable and has a owner it will have a data channel
I'm looking for recommendations and opinions for distributing a multiplayer closed, small-scale multiplayer alpha. The game will likely not be released on Steam, but I do have unused game spots available there and I'm not adverse to using it for testing. I need to be able to distribute, update, and allow clients to find and connect to non-dedicated sessions using some sort of existing friend/player system (i.e. Steam, EOS, or other). I'd prefer to use EOS since if the game is released to PC I would likely target the Epic store but I'm not sure what state that is in and how I could distribute the game during closed alpha/beta if using it.
I'm also not adverse to using an online system for testing that would not be used at release.
sounds like you need a solution which is primarily not time consuming
steam can do that, using something like advanced sessions you can get basic functionality working inside a day
provided you are somewhat familiar with how it works
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Called lamp on off!"));
if (PointLight->IsVisible())
{
PointLight->SetVisibility(false);
}
else
{
PointLight->SetVisibility(true);
}
}```ScreenDebug works on server and client but why `SetVisibility` works only on server?
it doesnt
you have to multicast it
but i wouldnt do that
i would use a replicated bool you set like UPROPERTY(ReplicatedUsing = OnRep_LampOff) bool bLampOff;
then void AWallLamp::OnRep_LampOff() { PointLight->SetVisibility(!bLampOff); }
then in your server rpc
you do:
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Called lamp on off!"));
bLampOff = !bLampOff;
}```
this will create a togglable lamp
and using OnRep will ensure new clients or clients who came into relevancy of the lamp will see the correct state
I will try this @meager spade. But I need declare void OnRep_LampOff, yes?
Thanks for tips 😃
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(AWallLamp, bLampOff );
}```
dont need to declare that in header file
and you need #include "UnrealNetwork.h" in your cpp file
Detailed information about how Actor properties are replicated.
Hey All, I'm making a force field actor that has health and can be destroyed by projectile hits. When I run a dedicated server the hits don't seem to register and the actor doesn't get destroyed. Also, the particles don't get spawned on all clients. What am I missing here?
I thought maybe I forgot to set a component to replicated, but I just double checked and all actors/components involved in this mechanic are set to replicate.
to be clear, the process works as expected when I'm the server. Just not when I tick 'run dedicated server'
i know in c++ servers dont call OnRep themselves
and you have to manually call it
but what is not working?
the overlap detection?
only thing i can think of is your projectile on server is not going where you think it is
might need to debug where your server thinks the projectile is
Does anyone have any experience with the Event CopyProperties in the PlayerState?
I'm trying to keep player state values after changing a level in multiplayer.
theres almost no documentation nor cases online. tried to find everywhere
would this be a good way of keeping player state properties upon level change or are there better ways?
its the only way really
what is?
CopyProperties
how do i use it?
NewPlayerState is the new player state
so you just set the properties on it
from your current playerstate
yeah
mind you i never done that in bp
i did it in c++, but it should be the exact same
does it hut
hit*
when i put a print there, it doesnt get called
where should CopyProperties be called from?
because i'm indeed not calling it
before/after i level change?
its called automatically
thats what i assumed
so in code
{
DispatchCopyProperties(NewPlayerState);
NewPlayerState->bOnlySpectator = bOnlySpectator;
}```
when player seamless travels, it dispatches CopyProperties
which in turn calls CopyProperties
and its called here
OldPlayerState->SeamlessTravelTo(C->PlayerState); inside AGameMode::HandleSeamlessTravelPlayer
so as long as you are Seamless travelling
the properties will be copied
@small compass Multiplayer Network Compendium by Cedric is a good read for that. It helped me a lot. Thanks Cedric! Pdf download here: http://cedric-neukirchen.net Examples in blueprints and c++
i'm currently not using ANY c++ in my project. but i will definitely bookmark your message @meager spade
im just showing that its called when seamless travel happens
so your bp CopyProperties will only fire if you are seamless traveling
yeah im trying to compare my bps with your c++ to find resemblances
and @scarlet osprey thx for the pdf :)
@small compass 👍the author is also frequently in this channel.
this prints the name correctly. right before it joins the session:
but i change the controller class on level change aswell
the menu, lobby and game have a seperate player controller
could that be a problem?
@meager spade
@thin stratus is it possible to have a persistent playerstate without using c++ when changing a level in multiplayer?
Well yeah
Mark the GameMode Seamless
It's not 100% persistent
But it gives you the option to pass over data with CopyProperties
exactly thats what i did
but no success
but the CopyProperties does not get called
i'm also switching gamemodes, is that a problem?
i have a MenuGameMode and a MenuPlayerController, then i enter the lobby and i use a LobbyGameMode and a LobbyPlayerController
Valandril the playerstate is tied to the controller, once you get rid of the controller the state will be eaten up by the gc i think. So that maybe one reason the copy never gets called. Not sure tho.
all i want is to keep the name a player filled in in the main menu when he is joining a session to persist.
Should i be doing this in a different way overall?
like maybe a savegame?
PlayerState has a name property by default
which is pulled from the OSS, or a custom one can be provided
yeah i noticed that it had it by default, i simply wanted to add a "points" variable
every game mode uses the custom one
(i started with ue4 3 weeks ago and trying to score an internship)
Good day everyone. I red some documents about multiplayer, but still don't know in how can I connect to other person through IP or Steam. Anybody can help me with this by providing an example or by showing how to do it?
In this video we take a look at the finished project and step through each of the features that will be covered in this series. We show our functional Main M...
this guide has steam implementation
from epic games themselves
Valandril Thanks. I already saw it. Will try to understand again
@rotund sapphire i checked and the player ID in the player State class is different
before changing level it was 499, afterwards it was 500
can someone help me with setting mesh with networking?
im trying to set random character models
@twin juniper do you have component replicates checked?
Sure
This is weird. Does a Character's Mesh have to be near the center of the root capsule (in terms of XY) for net rotation smoothing to work?
If I move out from the center (~>10uu), there is a strange out of jittering that I couldn't really get rid of.
got it all figured out
by any chance anyone have any good footstep sounds for outside like grass/dirt/sand/ anything around that nature?
Hi all, can UObject be replicated as an UPROPERTY?
the simulated proxy version on clients always get my UObject replicated PROPERTY equals NULL when I debug into OnRep_UobjectVar
I did set up ReplicateSubobjects function
you want to replicate a reference to it, or the object itself?
the object itself, I'm using it for some data that needs to be sync across clients
did you override IsSupportedForNEtworking in the UObject class?
Yes, I did
they can be replicated, and you have to keep a pointer to them in an UPROPERTY marked variable, otherwise GC will clean them up
most common use case would be UPROPERTY(Replicated or ReplicatedUsing)
Yes I do have that
I've tried basically everything I found on Google, not sure if I missed something 😄
show me the ReplicateSubobjects function?
that's right, I did set up my DOREPLIFETIME macro
and your IsSupportedForNetworking implementation in USlotHandlerObject?
yes
i mean what is it? just return true;
it should work then
there are few more functions i implemented, like GetFunctionCallspace and CallRemoteFunction
but those are required only if you're going to send the RPCs through it
there is a possibility that it does work, but there is a bug in your test scenario
the idea is to have those actors exist on the server, and have their "mirror" on clients
one of the example I've read has the UObject initialized only on server, with checking on HasAuthority
but in my case it still fails, as OnRep still delivers NULL value
so you do SlotStateHandler = NewObject<USlotHandlerObject>(this); from ASlotActor on server at what point?
should be from Authority
but the OnRep_ should still fire before BeginPlay client side
yes, I understand the HasAuthority part, but the OnRep_ is still unexplanable for me
without authority clients will overwrite the received object with newly created local one
that won't have a matching NetGuid
you put a breakpoint into OnRep_SlotStateHandler?
and the object is valid on server when BeginPlay is done?
yes
I debugged in the BeginPlay function as well, and all a server and two clients have the valid value of the object
(currently without HasAuthority checking, if with, then the game can't survive more than one tick, when one of my client Tick function accesses the status of the variable)
and the SlotActor itself is spawned at runtime or loaded from package?
it is spawned at runtime
it is server-sided actor
this function is a RPC, server only, and called from authored client owning the player
this is its signature
slot actor class is a BP class?
try overriding ASlotActor and USlotHandlerObject::PreReplication
also, implementing USlotHandlerObject::GetWorld
my scenario is more complex then this, but it just works
what should I fill into these function?
void UAttributeComponent::PreReplication(IRepChangedPropertyTracker & ChangedPropertyTracker)
{
Super::PreReplication(ChangedPropertyTracker);
for (USolsticeBuffBase* Buff : ReplicatedBuffs)
{
if (IsValid(Buff) && IsValid(GetOwner()))
{
Buff->PreReplication(ChangedPropertyTracker);
}
}
}
that is mine, mind that i am creating and replicating SubObjects from an ActorComponent
not Actor
so yours in Actor should just call Super, check the pointer for null and call PreReplication
it seems to me that UObject does not have any PreReplication
should I make a new function?
UBlueprintGeneratedClass* BPClass = Cast<UBlueprintGeneratedClass>(GetClass());
if (BPClass != NULL)
{
BPClass->InstancePreReplication(this, ChangedPropertyTracker);
}
this is mine
the body of it
hmm, I have no such thing for overriding
mine apparently isn't an override either, sorry
i did go through UActorComponent source code to see what they did to make it replicate, as it is also a UObject
yeah, so it seems that it's not so applicable in my case 😦
both of these are longshots
but i don't really see anything wrong with your code
and my UObjects replicate just fine
your case is simpler because you are not creating and replicating objects in a component
i do have a nasty engine caveat to deal with because of this
(when my object replicates, its outer gets ninjaed so its no longer the component, but the actor owner)
does it have GetWorld?
what do you mean by it?
that is UObject function, did you override it?
i do override it on all my UObject derived classes automatically
no, I didn't overide it
so i don't actually know if my UObjects would replicate without it
i assume they would
but can't say i am sure
if (HasAnyFlags(RF_ClassDefaultObject))
{
return nullptr;
}
return GetOuter() ? GetOuter()->GetWorld() : nullptr;
first part is because GetOuter()->GetWorld() is kinda undefined in the editor on the CDO
when you right click on event graph for context
it calls GetWorld()
and if it gets something it understands, even a nullptr
it lets you use functions that require a world context to work
doesn't work though 😦
I'm gonna head off for dinner and get back later
thanks for your support anyways, @winged badger
yes what
i wait for the tick in order to recheck if it can jump
so it doesnt call
retriggerable delay
you just need to replicate the user input
as in
is the jump button pressed or not
that sets your IsJumping flag
you also make a setter function for CanJump
that sets IsJumping to false if its false
its frustrating for me
and you simulate the rest
server doesn't really need to know anything except if the player is trying to jump
it knows the rules of jumping
so it can figure the rest out without getting in more RPCs
the server gets one call everytime i jump
cause i set it that way
what u dont understand
not when i trigger jump
not when is jumping
one when i jump
I don't need help with functions,thats why im in multiplayer,i need help with networking
your setup is all wrong
saying that, handling custom jumps in blueprint is a nightmare
you really need to handle it in the cmc
yeah so what issue you having?
i presonally dislike multicasting things like that
i would handle it inside the cmc via a custom movement
but you need to do that in c++
I never cared for c++
So being that far up in the project,starting to learn c++ while I can do it in bp will set up back a lot
all client does is send in he his custom jumping, cmc handles it and replicates it to other clients via the movememnt
yeah, but you will hit many brick walls in blueprint, especially on a big game
Yeah I have noticed some
but then again i find blueprints messy and disorganized, i use them only for a few nodes. then again i can do stuff just as quick in c++ as i can in blueprint
but if you never need to use c++ stuff, then its fine, there are many little games out there wrote purely in bp
but the bigger games would be crawling if they did it all in bp
You'll hit multiple brick walls trying to do multiplayer in BP-only. Certainly if you want to modify character movement anyway. Some stuff is just off limits.
Just be sure to test with a real-world connection scenario. Don't assume it'll work unless it does so outside the editor with some lag and packet loss introduced.
For some reason when any player leaves the dedicated server instance the server instantly hits array out of bounds, after adding them to the inactive list it seems
then crashes
[2019.06.23-15.53.04:794][374]LogNet: Warning: Network Failure: GameNetDriver[ConnectionTimeout]: UNetConnection::Tick: Connection TIMED OUT. Closing connection.. Elapsed: 0.00, Real: 271.82, Good: 271.82, DriverTime: 7.53, Threshold: 60.00, [UNetConnection] RemoteAddr: 127.0.0.1:17777, Name: IpConnection_0, Driver: GameNetDriver IpNetDriver_0, IsServer: NO, PC: BP_PlayerController_C_0, Owner: BP_PlayerController_C_0, UniqueId: NULL:DESKTOP-VRJ2G1O-A2C50F0643C9616A889006825146B5C5
[2019.06.23-15.53.04:794][374]LogNet: NetworkFailure: ConnectionTimeout, Error: 'UNetConnection::Tick: Connection TIMED OUT. Closing connection.. Elapsed: 0.00, Real: 271.82, Good: 271.82, DriverTime: 7.53, Threshold: 60.00, [UNetConnection] RemoteAddr: 127.0.0.1:17777, Name: IpConnection_0, Driver: GameNetDriver IpNetDriver_0, IsServer: NO, PC: BP_PlayerController_C_0, Owner: BP_PlayerController_C_0, UniqueId: NULL:DESKTOP-VRJ2G1O-A2C50F0643C9616A889006825146B5C5'
[2019.06.23-15.53.04:794][374]LogNet: UNetConnection::Close: [UNetConnection] RemoteAddr: 127.0.0.1:17777, Name: IpConnection_0, Driver: GameNetDriver IpNetDriver_0, IsServer: NO, PC: BP_PlayerController_C_0, Owner: BP_PlayerController_C_0, UniqueId: NULL:DESKTOP-VRJ2G1O-A2C50F0643C9616A889006825146B5C5, Channels: 9, Time: 2019.06.23-15.53.04
[2019.06.23-15.53.04:794][374]LogNet: UChannel::Close: Sending CloseBunch. ChIndex == 0. Name: [UChannel] ChIndex: 0, Closing: 0 [UNetConnection] RemoteAddr: 127.0.0.1:17777, Name: IpConnection_0, Driver: GameNetDriver IpNetDriver_0, IsServer: NO, PC: BP_PlayerController_C_0, Owner: BP_PlayerController_C_0, UniqueId: NULL:DESKTOP-VRJ2G1O-A2C50F0643C9616A889006825146B5C5
the start of the crash then it starts unloading everything ^
hey, is there an easy way to replicate a variable only when a certain condition is met (and if so how expensive is it)?
in C++ yes, cheap
how to go about it?
@spare glade The error is strange indeed. It may be because the max inactive players is 1 or 0 (for 0 it would not hit error i suppose but perhaps 1 is an ominous number). Check your gamemode settings the value should be 16 by default. maybe it solve the glitch once you set it back to default. Other than that, your game is kinda failing to maintain arrays which is rather strange and i have no idea atm what else could be the source of the error.
you can adjust the Replication (ie only replicate) when you like,
DOREPLIFETIME_ACTIVE_OVERRIDE(AAresWeapon_Ranged, CurrentFiringSpread, true);```
something like that
can toggle the property replication on/off
obvs only the server can do that
yea naturally :)
should i do multiplayer after i finish my game or as im doing my game?
multiplayer is not an afterthought
i guess i do it as i do the game
I'm new to networking and I can't get my animations to replicate to other clients. I'm using a multicast and it successfully changes the animation from idle without a weapon to idle with a weapon flawlessly across all clients, but for some reason it doesn't do the same for the movement animation.
here's the animation controlling portion of my FPSCharacter BP:
https://i.imgur.com/iie7PIW.png
only the server can call the multicast
so if they are not running on the server, they will never multicast
also why you sending a movement bool to the animgraph
that is terrible
animbp should NEVER receive values like that
instead it should pull the value
and you can easily just get the actors velocity to tell if they are moving
and that will be on server and client
and all other clients
what you are doing is trying to re-invent the wheel
and using more network resources in the process
I need some help figuring out why my new helicopter works for a little while and then stops lifting vertically. It works for 4-5 minutes before having problems, due to past experiences I thought it could be a replication issue. But I can't figure it out 😦
I'm a novice
when the elevation impulse fails I can still steer side to side and such, it just starts gradually losing elevation like it is idling while holding throttle input, print screen shows 1.0 as the correct value for the upward input when it fails
if I exit the chopper, my new pawn's actions work just fine
so I don't think the game is messed up
The fire continues to burn, trees still disappear, et cetera
anyone have a problem where like an AI character capsule separates/jitters away from the skeletal mesh in dedicated server?
wait it looks like the net smoothing only applies to the meshes and not the capsules?
well, I changed it so my WidgetComponent is attached to the mesh instead of the capsule and you can't really notice the jittering anymore, even though it's happening
because the mesh is smoothed
doesn't feel great but I figure I'm probably gonna have to write a custom move component for my AI dudes ultimately anyway
I'm researching the OnlineSubystem interfaces IOnlineUserCloud and IOnlineSharedCloud, and I am looking for examples of their usage to make sure that I am aligned with the industry. Does anybody know of any public/example projects that use those two interfaces?
Interface links for reference:
https://docs.unrealengine.com/en-US/API/Plugins/OnlineSubsystem/Interfaces/IOnlineUserCloud/index.html
https://docs.unrealengine.com/en-US/API/Plugins/OnlineSubsystem/Interfaces/IOnlineSharedCloud/index.html (edited)
has anyone seen this kind of log message when trying to call OpenLevel to connect to the server?
Ignoring restart handshake request, due to < 10 seconds since last handshake.
@rotund sapphire seems to be good now, i just need to leave it on a higher number for now on or default. thnx
Do RPCs batch? and would I even want them to?
might be a stupid question
I have read they are sent as soon as you call the function, so I'm assuming no
reliables are batched
as they are deemed reliable to, so if they don't get sent through straight away, they will eventually
unreliable will be dropped if they cant get to through
for some reason the engine can decide to not even try to send unreliables
you'd think they are unreliable on the network layer only - as in, not resent when the packet is lost, but it goes much further than that
it can just discard them when it thinks the connection might be busy
I have big problem. How can I add multiplayer to destructible object? Creating custom event for multicast replication or adding replaction for function above?
anyone know how to setup the replication graph to let a specific group of connection sync to each other. I trying to create a UDAReplicationGraphNode_AlwaysRelevant_ForConnection node , but I dont know how to add some group of actors to this node
So im trying to connect to my dedicated server from another computer in my house. This is what the server log is showing. It does this endlessly and I never fully connect and move to the playable map. Just a black screen on the client. People outside of my house are able to connect successfully though. Anyone know what would cause this?
I tried to use RouteAddNetworkActorToNodes , I dont know how to setup FNewReplicatedActorInfo to make it added in UDAReplicationGraphNode_AlwaysRelevant_ForConnection node
Has anyone played around with the Physic Error Correction settings in the Project Settings with multiplayer testing?
If so, how reliable has it been to see less jitter with PhysX actors and what values are appropriate for fast-moving vehicles?
I've messed with it but not much. I'm waiting on Chaos to deal with networked physics.
Why this destructible wall don't replicate to other clients? This is my BP functions:
Clients shouldn't call Multicast RPCs.
@worthy perch so how can I do this? property replication?
Replicating the health of the destructible would be better, yeah.
And have the clients change the appearance of the destructible via OnRep.
tell the server to do the multicast
@meager spade you mean health property?
Something like health needs to be changed on server only, and replicated to everyone
These two things need to happen, anyway
Okey, I think I understand this. So players shoot on destructible objects, server changes healt and replicate to everyone, I will try do this - thanks for tips
Hi, I have a problem that i dunno why it's happening, I have a spectator camera pawn that's os possessed by a specific client -- it's replicated and all fine, this spectator camera follow another player (on server and client for sure as it's replicated), but when this player is beyond certain range all of his child actors disappear and become not replicated anymore (from the spectator camera view), when he's back to the initial area everything appears just fine ,, any clue why this could be happening ?
without the spectator pawn being replicated
its net relevancy position doesn't change
what should happen is that this player and his child actors that the camera pawn is following should be replicated all the time since the spectator camera is in it's relevancy
so when you get out of 15k UU range, everything suddenly becomes not net relevant and culled
only exception being the current viewtarget
sorry, you did say it is replicated
yea
its still a distance based net relevancy culling
where is the spectator pawn physically when the observed player gets out of range?
why this happend lol, the pawn is on the head of the player
he was actually over his head
ok
is it there on the server, or are you just teleporting it around locally on tick?
tick yea
because its server position determines net relevancy
doesn't matter where it is on client
the server is moving then replicates to client
i'm printing postion on server and client and they r both the samew
same*
try attaching the specatotor controller to the spectator pawn
you have a checkbox for it in class defaults
Could I get some clarification on RPCs? https://docs.unrealengine.com/en-US/Gameplay/Networking/Actors/RPCs/index.html This page says that:
They must be called from Actors.
Does that mean that the RPC function itself (e.g., marked UFUNCTION(Server)) must be called by an Actor? What if another object calls an Actor function that calls an RPC?
Designating function replication across the network
To give a more specific use case: let's say I want to call an RPC from an AnimNotify. Can I call a function on the Actor that internally calls the RPC? Or can I call the RPC directly from the AnimNotify?
@idle blaze you can call RPC from server to clients by anim notify if this server will call this notify too, and call RPC from client to server from anim notify if the owner of the animation blueprint is local
In that case, I'm confused by what it means that "[An RPC] must be called from Actors." Does it just mean the RPCs must be defined in an Actor?
@idle blaze hold a second then let me check my anim BP, may be i have used some
there u go, and it works fine
Interesting, thank you.
yw
@winged badger so i have attached the player controller to the pawn and still the child actors of the player i'm spectating disappear
well the player donesnt disappear cuz i'm setting him always relevant, but when i uncheck this, it disappears too 😄
AMyChildActor::IsNetRelevantFor(params)
{
if (GetAttachParent())
{
return GetAttachParent()->IsNetRelevantFor(params);
}
else
{
return Suoer::IsNetRelevantFor(params):
}
}
sadly i'm using BP
any use of replication graph?
nop
i'm guessing that the server doesnt know where the client is so it doesn't replicate the player to him
so as long as the server of the spectator pawn is in the same area of the player, he should be relevant right ?
well
it should be enough if you teleport the spectator over players head every 1-2 seconds
and interp only locally on client
you don't even need to replicate its position
and i am pretty sure about that, as i use a similar setup for RTS controls
in my setup the server is moving the spectator pawn in tick to the player camera location, and since it's replicated the client follows
but still this problem exist frim nowhere lol
the spectator pawn is set only relevant to owner tho
Why projectiles from weapon works only client to server, and client to client but no for server to clients?
I declare this void I character CPP:
void ServerFire();```
no clue, you probably did something wrong
but that should work like you said, Client to Server and server to client
as long as you spawn the projectile on the server
and its set to replicate
Why this shoot spawn projectile works only on client -> serwer?
{
if (ProjectileClass != NULL)
{
UWorld* const World = GetWorld();
if (World != NULL)
{
const FRotator SpawnRotation = GetControlRotation();
const FVector SpawnLocation = ((FP_MuzzleLocation != nullptr) ? FP_MuzzleLocation->GetComponentLocation() : GetActorLocation()) + SpawnRotation.RotateVector(GunOffset);
//Set Spawn Collision Handling Override
FActorSpawnParameters ActorSpawnParams;
ActorSpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButDontSpawnIfColliding;
// spawn the projectile at the muzzle
World->SpawnActor<AFPSGameProjectile>(ProjectileClass, SpawnLocation, SpawnRotation, ActorSpawnParams);
}
}
}```
In projectile constructor I have:
```SetReplicates(true);
SetReplicateMovement(true);```
if i want to pass a string from the client to the server using OpenLevel, would I pass it in through the Options parameter or would I append to the level name ?StringIWantToPass
?Something=Something
?Key=Value?Key2=Value2?Key3=Value3...
Just to help clarify what @meager spade said.
Thats how the Options string wants to be formatted.
weird question, is there a way to write totally separate files for server and client?
thanks guys, u guys are life savors as usual
lets say i want a door in my game, i can have the door.cpp and door.h, then in the door implementation i can have something like 'if has authority, open door'
what i want is a completely separate file for door_client and door_server, and only door_server has the function open door
if that even makes sense
@fossil spoke
i might not even necessarily need a door_client if the client can't interact with it, like if its an automatic door for instance
i just dont want to deal with all the if (HasAuthority()) junk to find out my roles
Typically this is done all-in-one file
#if WITH_SERVER_CODE
void OpenDoor();
#endif```
Yeah use the Preprocessors to block code you want to be separate for which target your building for.
not the cleanest but if it works what the heck
You can do the inverse, #if !WITH_SERVER_CODE but nobody does that
im assuming WITH_SERVER_CODE is true for when it is the server running
Generally, your server should be doing a superset of what your client does.
Nah, conditional compilation is determined before packaging.
YourGame_Server.exe
YourGame_Shipping_Win64.exe
etc
ah, does it still work on the pie environment?
Its UE_SERVER though isnt it? @severe widget
guess testing is easy enough
Never heard of WITH_SERVER_CODE
is there a list of these preprocessor defines?
Build.h has them.
🤔
/**
* Whether compiling for dedicated server or not.
*/
#ifndef UE_SERVER
#define UE_SERVER 0
#endif
thanks
my very rudimentary test is telling me that it does not work in pie, ill keep trying
PIE won't tell you anything
i guess all i really have to do is just change if UE_SERVER to if true when testing out dedicated server functions in pie
It's WITH_EDITOR, UE_SERVER, UE_GAME, etc, etc
all set to 1
PIE is basically most things.
You wanna do a different client and server exe to test compartmentalization of code.
Yeah PIE isnt where you should be worrying about that
So its in the GAS plugin?
So thats why i cant scope to it lol
UE_SERVER isn't in here.
UE_SERVER is in Build.h, its probably just saying that we are building for Dedi
TargetRules.cs is where UE_SERVER is added
Its also defined in Build.h
Well, only if it isn't pushed through by UBT
Yeah
Anyway, it appears UE_SERVER, UE_GAME, and UE_EDITOR are mutually exclusive
if you want your code to legit only work in a server, UE_SERVER is your preprocessor macro @arctic bone
thanks homies!
hey i want to make a coop multiplayer game in c++ any where i can see a tutorial where to do this ?
Gonna need a whole lot more details
like what?
Like what game is it ? If you're doing multiplayer physics, the tutorial is going to be one word - "no"
Multiplayer is a whole field of work, not a feature
Is it a shooter ? Vehicle game ?
shooter
In that case you basically have multiplayer working already
You want to look at sessions (something like the advanced session plugin is a good start), and any tutorial on multiplayer will explain the concepts you'll need for game features
I have been looking at some tutorials but the ones on youtube only show blueprints
and one said to replicate a variable inside the game instance
Of course, the game instance isn't replicated
Dunno how BP gets it to work
So replicate another class
If you're new to networking in UE4, C++ is not where you should start, tbh
Hey question. I got a level cloud bp that moves around the world. Should I be spawning the cloud bp in from gamestate because the actor dropped in the level with replicate movement doesn’t seem to update its location to a newly joined player . Figured maybe if it’s spawned in it’ll pickup the location data
I tried on begin play for non server to set the bp location to the servers Vector. I have an idea that maybe the vector of location should get stores to a rep vector variable and client side it just continuiouslt keeps current location to that var