#multiplayer
1 messages · Page 89 of 1
Yeah :x
What you had in the pic will never work cz increasin the int is locked behind a condition (them being alive)
Which makes no sense
Thats why im sayin first increase the integer, without conditions
I was thinking the player thats alive would have the games won variable increased though?
Rather than the player thats dead has a death count variable
You should get that player directly instead of iterating based on hp
How can I do this?
Well you surely know which player died when someone dies right?
I need to know the alive player
You also know who killed them no? The one dealing dmg.
To call the win widget for the alive one
Good point
But say
What if the other player died to the level
Is it always 1v1?
Yea
Then take the one thats not the dead one
With only 2 players youre right, cz iterating doesnt make a difference and can still be optimal
Cz you had the order wrong, individually the code parts you had are good
- player dies
- check player array and see who's alive, for those increment the integer
- check if anyone has won overall
Is this not what I did?
Sorry if I missed something
If I were to get that variable in the widget is this correct?
I think if you were to show me it would help
When you can
yeah thats correct c:
Ok! Maybe tomorrow or something we could go through this?
Thank you : )
yeah just PM me or something, cz here I wont see it :X
I added you
Quick question regarding Seamless Travel and Transition Maps. Does the Transition Map have to have the same GameMode/PlayerController/etc configured to actually work or can it be completely blank?
Like this? Or do I need to set the same GameMode/etc as the Level im transitioning from/to?
no
why would player state 0 be local player?
player state 0 is the first player to join the game
How do you get the local variable then?
Get owning player of the widget, get playerstate from that.
Got it
Casting isn't getting.
From the owning player, get the player state, then you can cast to your custom playerstate.
Ah got it
I have this session created and working properly but on joining server the pawn is not spawned and the game freezes. So, GameMode wouldn't itself spawn a new pawn for client on joining session and I do have to manually spawn pawn on client right?
The solution is to go to the game mode BP and check it's parent/native parents which resides in the project for this GameMode=/Script/CTFTask.TaskGameModeGameplay is to be set as game parameter in travel url
if you don't define a struct's NetSerialize function, where does the default netserialize functionality come from? edit: found the same question #multiplayer message
reason im asking is bc i need to write a netserializer for a custom target data struct that contains another struct and i'm not sure what to call to serialize that
how do you usually handle server destroying the projectile before the client projectile actually hits something? I wanted to play particle on hits
Guys, I'm running a gamelift aws server and when I choose a larger c4 server I get this problem Current limit of instance type of c4.xlarge have been reached.
Does anyone know how to fix it?
Buy more instances of large servers?
I have informed myself and I have increased the quota but I tried it again and it still does not work for me
Maybe ask gamelift?!
what do you mean by gamelift this is what gamelift uses to set up dedicated servers using the ec2 service
The problem is that I can only use c4.large and with this the server gives me problems since it prevents me from migrating data for clients
Erm, sorry, ask amazon.
delay destroying could work?
Don't destroy
set it to some state and set its lifetime
Can anyone see why this would work for both client and server when server runs the code, but when client runs it, it only effects the clients side?
Nevermind that, that's not how you want to replicate state
Repnotify my dude
Here's how things work with repnotify
Client action -> run on server event
Run on server event -> set replicated variable (you'd set bIsLightOn)
EVERYWHERE -> runs the RepNotify function when the variable changes (this is where you'd set visibility)
so your telling me.. that ive been doing this whole server to client / multicast, and all i have to do.. Is use a has authority switch, and just set the variables to change to repnotify?
Don't even need an authority switch. Just only ever set the variable serverside. Authority can be used for gating events that can happen on either side
hell you can probably do it clientside too and get some janky "prediction" out of it
Input -> toggle light bool -> also request server to toggle light bool
Onrep_LightBool -> change the things that depend on lightbool
Not sure what will happen but you might just get an instant light
yea, im confused af
do you have an interaction interface or component or base class?
Are you trying to do general interaction? Get close to thing, press E , have it do the thing?
im using an interact interface
what
oh interface
ok
so just do this
Input -> run on server event (pass over ObjectToInteractWith)
Run on Server Event -> call Interact on ObjectToInteractWith
that's it
i interact with object, it brings up a Widget, i pass the info for the specific object when clicked, then run the code i showed
ok, so i still use the server replicated custom event, yea?
just not the multicast
correct
Just tell the server the actor you want to interact with
Is this in the widget?
that is in the widget, yes
Show a screenshot of the widget so we can know what you're actually doing and what it looks like
in game, in the world
is there a reason why in the listen server, the animation of character will get choppier the higher the latency is to the client?
Each object only has 1 thing it does in response to interaction right?
yea, i have a public variable that is set to one of those cases ie. Light Teddybear, Teelvision, etc
delete all that case stuff
its no good
Since you have an interact interface, each item does whatever it does on interact
This is for nearby object right? So CycleObjects changes which object is "targetted" and Interact does the interaction, right?
are you free to VC for a few minutes so I can share screen and show you?
I'm at work on a phone lol
i may not explain correctly
Is this the gist of it?
I'm guessing CycleObjects cycles through nearby interactable objects
since widgets are not replicated, it'll have to go like this
ButtonPushed -> call event on Pawn or PlayerController (whichever one makes more sense), passing in the object you want to interact with
Pawn/PlayerController
Event from widget -> call ServerInteract(passing in object you want to interact with)
ServerInteract -> call Interact on passed in object
Object
InteractFunction -> do the thing
Widget tells Pawn/PC tells serverside Pawn/PC tells the item that it's getting interacted with
so basically i have to put the code inside the actual object, not in tis widget
yes
yup
lmaoo i didnt realize widgets didnt replicate
the widget doesn't care, it just tells it its being interacted with
it was werid that it worked for server, but not for client
Or rather, it tells the pawn which tells the SERVER version of the pawn which tells the item
Not weird at all, the server can do whatever it wants
so that multicast, because it was in a widget, was ONLY running if it was the server running the code
the server is pretty much playing a single player game
well you just cleared a lot up for me. thank you very much
Your setup is a bit more complex than most peoples as you have UI involved
i like to make stuff hard for myself apparently hahah
But at the end of the day, it pretty much looks like this
Something tells the serverside version of itself (run on server event) that it wants to interact with a certain actor (passes over an actor ref)
Serverside version calls Interaction interface on the passed over actor
Actor does its thing.
You just have to have the widget tell the local version of the pawn/pc to kick it off
that makes a lot of sense after you explained it
With the previous information about Unreal Engine's Server-Client architecture and the common classes we can divide those into four categories:
Put that Venn diagram as your wallpaper
I was so confidant in my abilities till i started multiplayer stuff lol
Guys, a question with the new aws update, should I update my gamlift unreal sdk to connect to the fleets?
I feel bad to keep messaging, but i fel like im doing something wrong lol I thought i did what you said to do, but its still only working if server presses interact. here is the whole code incase something i did prior is the problem?
- When you interact.
- Creates that widget, passing the info along,
- When you click the interact button.
- The code on the same blueprint that was interacted with (what you said to do? lol)
its just a stupid light haha i feel so dumb
Adriel told you to use the PlayerController or Pawn
You can't run server RPCs in random actors that aren't owned by the calling client
Read the Network compendium properly. It's all explained in there
the code is in a pawn
The RunEvent?
yes lol
In your own pawn?
The one that is possessed?
Cause only the owning local client can perform server rpcs in that
Does it maybe make sense to try to create a local client AAIController for some level of movement/behavior prediction in a networked game?
I made a pawn BP that acts as an interactable / possessable object. I take "control" of that object, then show a widget, that allows you to interact
Afaik CMC prediction only works for actually client controlled character
the code is within that Pawn, not my player
We meant your controlled player pawn
Not any that is randomly standing in the level :P
Widget Button Press -> GetOwningPlayer or GetOwningPlayerPawn -> ServerRPC with interactable obejct as param -> CallInteractEvent
Not all
But your are restricted by ownership
You can't call server rpcs in non client owned actors
that would explain why the code wont run at all...
Pawn/Character (if locally controlled by the calling player) PlayerState and PlayedController are the basic ones that worl
Work
After that you have to ensure that any other actor is owned by the client
Ownership can also only be assigned by the server. So you can't just do that on the client either.
That's usually done when spawning replicated actors by giving it the PlayerController of a player as owner
Or on an already spawned actor by calling SetOwner
But again only server can do that
And only one owner per actor is possible
Why are you possessing?
You can also use a different actor as owner than PlayerController as long as that actor is somewhere owned
So a chain works
What is the actual game mechanic you're trying to do? Just explain it as a little story.
But again this stuff would be clear If you read the compendium
ill have to read into this more. i used to do things differently when i was working with multiplayer a year or so ago, but i dont rememeber w hole lot about it
Tell a story.
The player does ?????????????? And ?????????????????? happens.
you are able to play as a ghost, and can possess objects around the map to do things depending on what object you possessed. lights can turn on and off, similar to a tv, books can be thrown, suit of armor may be able to move
Ok so that's totally different from the typical interaction system.
Are you still the ghost the whole time or do you literally control and drive around the thing?
you take control of the object, everytime. theres a camera that your view changes to per object
Ok
but only some will move, but thats not really important right now if i cant turn a light on and off haha
So you really need the UI widget or would you rather just have controls do different things when in a prop, like how GTA you use the same controls to drive or walk
id prefer the UI so that we can add other options as well
Yeah, trying to make prediction for server controlled (AI), it's AI controlled because all the units are RTS units so have their own logic to follow, while the user just issues commands. Wondering if it makes sense to create a local AAIController to do some of this prediction work for the client in this case. Or if there is some simpler solution. It would be a lot of work but trying to figure out the best approach
if theres something i SHOULDNT be doing thats making this rough to do, i can adjust, but i figured this would be okay to do this way
The big thing that possession changes is the fact that you are directly controlling the possessed thing
Where before I said you had to route your request through your pawn
The object IS your pawn
So you can just do a direct run on server event within the thing
did you see the picture i sent?
is that what you mean? cause thats inside the possessed objet already
Are you going to make a widget bp per pawn BP?
How does the widget know what actions are available
No don't do that
in the level, when i add an instance of the object, I change the string to one of those cases
Nooooooo
in this case, i have a light, i call it "light" and it runs only that code when interacted on the UI
Nah
i changed that to repnotify, but clearly its wrong lol
Ok how many actions do you want to support
like, how many unique objects essentially?
right now, im just trying to interact, and change what happens when interacted, based on which object it is. Like for all the lights, itll just control a point light to turn on and off
im mainly tryin gto make placeholder code that works, that we can copy / paste and adjust, you know?
Ok the first main decision to be made is whether or not you're going to actually use possession
well, the main reason i was possessing everyone, was to use the camera inside the object
so you can watch what happens around the object,
You don't need to possess to do that
think of like a prop hunt game i guess?
Can some props walk?
What I'm getting at, is doesn't make sense for all props to have a single base class? All of them.
technically, its a parent, so i can absouletly determine if it needs possession or not instead of doing it this way
cause your right, they dont ALL need it, i just thought you had to to use its camera
It gets tricky because you fundamentally have two categories of objects. Those that can walk around, and those that can't.
i can deff set a public bool, and switch between UIs or w.e but id assume this way SHOULD work
i dont know a whole lot about multiplayer lol obbbbviously, but logically, it makes sense haha
I'm thinking your base class should just store a text variable which is what is displayed by the ui. I should just have a do-action event which is what is called by the UI
Don't switch on strings or whatever, that's gross.
I mean, i can make a child for each unique object, and run the code directl y within each?
in my mind, im thinking that i can then just set code in each seperately, and pass along that specific object instance when interacted with, then run the code for that object itself from the UI 'interact event'? but i feel like itd be basically the same as im doing now, just minus the switch
It says there is no game in session to join but joins successfully?
Set to BP GM, not the C++ GM
Hey everyone, hoping to get some assistance on an issue I've been trying to fix the last few days. I'm thinking it might be a fundamental lack of understanding but after so much time it might be best to get another opinion.
I'm trying to test my multiplayer game in UE PIE with one player as the listen server. In the character's PossessedBy() function I'm calling a CreateHUD() function from my player controller.
In CreateHUD() I'm calling the native function of GetHUD() from APlayerController::GetHUD(). The player on the listen server immediately gets a nullptr for this function. The clients do not return null.
Can anyone help me understand what I'm missing?
Are you calling Super in the PossessedBy function first?
Yeah I am
Ah. My bad, the GetHUD, not the controller is null.
That's odd. All AHUD spawning should be done before the player is given a pawn according to GameMode code.
Yeah, I've been stuck on this one for a while. PossessedBy function below if it would provide any additional clarity.
void APABaseCharacter::PossessedBy(AController* NewController)
{
Super::PossessedBy(NewController);
// Player State
ABaseCharacterPlayerState* PS = GetPlayerState<ABaseCharacterPlayerState>();
if (PS)
{
// Set the ASC on the Server. Clients do this in OnRep_PlayerState()
AbilitySystemComponent = Cast<UPAAbilitySystemComponent>(PS->GetAbilitySystemComponent());
PS->GetAbilitySystemComponent()->InitAbilityActorInfo(PS, this);
AbilitySystemComponent->SetAvatarActor(this);
AddCharacterAbilities();
// Set the AttributeSet for convience attribute functions
AttributeSet = PS->GetAttributeSetBase();
// If we handle players disconnecting and rejoining in the future, we'll have to change this so that possession from rejoining doesn't reset attributes.
// For now assume possession = spawn/respawn.
InitializeAttributes();
// Set HUD
APABasePlayerController* PC = Cast<APABasePlayerController>(GetController());
if (PC)
{
PC->DisplayControllerID();
UE_LOG(LogTemp, Warning, TEXT("Created %s"), *FString(__FUNCTION__));
PC->CreateHUD();
}
}
}```
The first thing I do in CreateHUD is check if GetHUD() == nullptr:
```void APABasePlayerController::CreateHUD()
{
if (GetHUD() == nullptr)
{
UE_LOG(LogTemp, Error, TEXT("GetHUD() returned null"));
}```
Largely following GasDocumentation but trying to use HUD instead of just a widget: https://github.com/tranek/GASDocumentation
I'd maybe breakpoint in the two places HUD is created in the controller and see if they're ran first and if not, why.
But beyond that I'd maybe. critisize this by saying that character shouldn't care about this UI. Maybe at most throw a broadcast when pawn changes that the UI or AHUD could use. But tying UI to the character class isn't a good idea outside of some registration.
delegate auto replicates if called from a net multicast reliable event?
Does it matter how multiplayer is implemented? (Blueprints, or C++) pros and cons of each?
You'll figure it out as you go. Start doing a mechanic in BP but you'll eventually find when you want to move stuff to C++
There are minor differences to each. EG stuff like in BP OnReps are also called from setting the value on the server. In C++ you have to explicitly call the OnRep or update function after setting the value. RPCs are mostly the same.
The major thing you'll find is that BP lacks a ton of tools that make a lot of networking better. You don't have FastArrays, prereplication conditions, custom serialization, replication graph, etc.
So for performance and optimization. I would want to go with c++. (Gotta go learn it then lol)
from func1(); to func3(); will be called on every client by server?
Server_Reliable() { NetMulticastClientReliable();}
NetMulticastClientReliable(){func1();}
func1(){funct2();}
func2(){func3();}
Hey, thanks so much for giving me your insight/opinion! It really helped me to rethink my approach. I think I was just all over the place and stuck in an abyss of frustration.
Overall, I set my HUD on the PlayerController within the BeginPlay() where GetHUD() did not return null. In research I saw lots of things saying the HUD is not replicated to the server which got me to thinking that I should be creating the HUD like I would in a single player game.
For the clients I did the same in OnRep_PlayerState() for the PlayerController and it seems to be working now. Honestly, I may need to research this portion more but I'm mostly just trying to learn GAS right now so trying to follow along with the documentation provided by tranek.
I have a replicated UObject and i'm trying to call rpcs on it (client->server) it seems to call the implementation function on the client instead tho not the server
Remove _Implemenation from the call
the call doesnt involve Implementation
Every client the Actor in question is relevant to
A server RPC either fails or calls server-side
It can be called client-side only if you didn't really call the RPC
But the local version dispatched internally
hm
I'll see if the stacktrace can give me more info
calling Server rpcs on the player controller works fine
It's probably an issue with replicating uobjects
stack trace looks completely different in the player controller vs the bugged object
How do I get all the player starts in a level?
Ok, thank you
If you're doing what I think you're doing, dig into the functions you can override in GameMode
I'm working on a multiplayer game but my pawns get visually culled even though there is no max draw distance. It only happens when the pawn is possessed by a human controller. If the pawn is possessed by an AI controller or just placed on the map, it does not get culled. Does anyone know what the problem might be?
relevency distance?
they culled visually only or do they get yeeted out of existance / end play?
The relevancy is set to default. They only get culled visually, if I shoot for example, that still work so the pawn is still on the map and replicating.
I'm testing it on a clean level, there is no cull distance volume on the map or anything like that. 🤔
Anyone know why my Physics enabled component does not spawn on client initially when the component is replicated? I found that I can get it to spawn by switching authority and setting simulate physics, but then the server it does not spawn...
Hmm, what does it look like in each?
You know that the UObject should be recursively outered to an Actor that replicates, right?
Placed in map actors are not destroyed when a client gets out of their relevancy range
Yep this was the only object I forgot to have the controller own it was a problem on my end
Oh yeah replicates and owned by the client
Hey Guys needing Tips
so this is a projectile when overlapps do stuff everything works except it wont ignore the target when it has "Death" Tag it still Collides i excpet its due to the server counting an overlapp and the client also ?
any ideas on how to ignore targets with tag ?
Is it "Dead" or "Death" tag that you're applying when the actor is marked as dead?
Does Enemy or Terrian work?
:O:O:O
y enemy and terrain work
@sinful tree just realized im applying "death"
omggg
been at it for days xD
lets try
So it is better to get the state from a parameter you know. The tag system makes difficult to track bug.
Make an interface for the characters has tags
Is it "dead" or "Dead" you're applying? Your logic is checking for "Dead".
Hello comes with checking dead exists or not?
exist
The video you posted is server or client?
but since the server can sense the tag since its printing shouldent it be replicated then ?
im applying on server
hmm
It is the variable in Actor which is engine contents
Everything is replicating from server to client correctly, Just that Players cannot see each other. What can be the problem?
@twin juniper there is an option to hide for other players
if your using the fps template
in the player BP
It is not replicated.
You mean for the character or Game Mode?
The first thing I see as being a problem, is that if this is a replicated actor, then the client would also be triggering the overlap event. Since Tags isn't replicated, the client's version of the actor could be doing things you're not expecting.
You may want to put in a has authority on the overlap to make sure it's only the server performing the logic.
there isn't
@twin juniper hmm i rember doing it once dont rember where try googling it
@sinful tree hm using authority still gives same response
The mesh on your characters can be set to "Owner Only See" or something like that. I think the FPS template doesn't have anything visible for other players.
@sinful tree thats the one
ok but tags not being replicated there is no workaround for that ?
or do i need to cast to player begin overlapped and check the dead option instead
Thank you man. It was in mesh component of character BP
If the Has Authority isn't fixing it, then it wouldn't matter. Are you using any OnHit or additional Overlap events in the projectile or on the character?
yeah i am
hmm lemme check i think
the weird thing is with my melee attack on the char BP
im using same logic but that works
the projectile however is spawned on the server
by*
ok so this is weird
thats cause its not being replicated
i suppose?
im going to try applying the tagsa locally to
yeah so that fixed it 🙂
however on the respawn it dosent collide gah
thers always sometihng
You could OnRep for your isDead variable to apply tag on client side
hmm ayee never used on Rep
what dose that entail ?
i mean i would prolly go watch tutorial or read up on it before using it since ive never used it
Use of OnReps is essential
Blueprint deals with them differently (incorrectly), but they are still used a lot.
what happens if we call server RPC from the server?
I think the system just drops the RPC
no, it will run it
On which side?
I think they have assumed that the RPC being invoked from the server is Client RPC. Correct me if I am wrong
maybe it is dropped 🤔 i am sure it never got dropped, but yeah
dont think i ever had that issue
thats what i thought
What is the best way to implement projectile firing in multiplayer? Using multicast?
i mean i have been using ue for a fair few years, i am pretty sure it was not dropped
If it doesn't get dropped then I can just call OnFire for server and server RPC for clients, right?
depends if you want true projeciles or fake projectiles
true projectiles, server just spawns a replicated actor
no multicast needed
Sorry I mean same function
But it will work for all the purposes such as hit, right?
well you normally try to have fire initiated by client, to reduce "input" delay
You mean simulated proxy?
then have the server spawn the projectile
but we normally hide projectle spawn behind muzzle flashes
so client gets to see muzzle flash instantly
but the prjectile is slightly delayed
For the simplest possible solution, you call a Server RPC which spawns a replicated projectile
It's "good enough" for a relatively low number of projectiles, and muzzle flashes and sounds do quite well to hide latency too
It is for a job test task
Usually just server spawns a replicated projectile for most of the multiplayer games.
Yeah, they disappear after some time and firing is limited with delay. I think it should be fine
Understood.
Thank you everyone for the help
Hmmm, I've never tried. It means just working like the non-RPC function? I'll give a try but thank you and Kaos to clarify it in case to misguide others.
Yeah, just gets called like a normal function. The Server can call any 'Server' RPC at anytime
Is it viable to make a multiplayer shooter in Blueprint or are there issues with that?
Just out of curiosity, when we setup online subsystem in unreal using any service you may such as steam or xbox, if you have a dedicated server, how do you manage fault tolerance during deployment for a massive scale Multiplayer?
4 player co-op, yes
anything more complex... i wouldn't recommend
What's the downside?
Blueprint has only a small fraction of the engines multiplayer systems exposed to it. Anything that requires high performance or security needs to be in C++
Also the overall increased complexity of MP projects usually makes it harder to cope with in BP
Alright thanks for the answer
Hi, could someone tell me what happens on the server on BTT-tasks and what on client? Or does everything happen in both server and client if you dont add server functions to it. I'm currently not sure if I should check authority and add server functions inside of the BTT's. Thank you
AI controllers that run BehaviorTrees are not replicated by default
unless you make them replicate, all BTs and BTTasks will be server only
@winged badger thanks
Is Game State replicated by default?
Yus
I have this member variable of GameState but it isn't replicating
But it has nothing with what you asked and what I answered
GameState replicates by default
There is not Owner for GameState
Your condition make no sense
And makes no effect most prolly
Oh Okay
I have been following gorka games rpg tutorial, but I want to make a multiplayer rpg, just not sure where to start with implementing it, or when, or how. Any tutorials that you guys suggest I watch to start understanding multiplayer implementation?
Like, should I already be implementing multiplayer or wait? Theres so much I dont know about it
Needed to include header Net/UnrealNetwork.h
what will happen if I press the Action key? where will I end up?
void OnDelegateEvent();
GameState->DelegateEvent.AddDynamic(this, &AMyClass::OnDelegateEvent);
PlayerInputComponent->BindAction("Action", IE_Pressed, this, &AARMACharacterBase::Server_Event);
void Server_Event()
{
DelegateEvent.Broadcast....
}
void Multicast_Client_Event()
{
//some logic to be called on all clients by server
}
void OnDelegateEvent()
{
if(HasAuthority())
{
log("Called by authority");
Multicast_Client_Event();
}
else
{
log("called by no authority");
}
}
if I run the game with 3 clients, and spawn an item it shows on all clients which is correct.
but if I run with 4 clients or +4 clients, the item only shows on 3 clients
what can cause this issue?
so just a general question, im making a "2D" platformer, but just using a sprite on a capsule. does anyone know the direction to look for what i need to replicate for updating to the correct direction of the sprite? basically when the player inputs left or right i flip the control rotation and actor direction, so my guess would be, do i need make some dummy variable that is set everytime the player flips left or right to replicate?
Can anyone help me with my lobby networking? When the players are in the lobby, I am trying to achieve a player readiness system, so when a player presses the ready button, all the other players see the text update like "Going to Ivan (2/6)". But for some reason it is not working, and it seems as though my casts to the gamemode do not work (Sorry for bad grammar, I'm Russian)
Here is my gamemode script
Here is my PC
Here is my Ready button code
And here is the label code
Another thing that would be good to mention is that I am using Advanced Sessions Plugin
I've been fighting this issue for around 5 days and it seems I might be going mad
Regarding the cast to GM, I don't know about advanced session plugin but while changing the level (travelling) you need to set game mode explicitly
Here?
Not this, you are setting up online subsystem right?
Wdym?
OnlineSubsystem? Multiplayer?
Are you creating session in game instance class?
This is al my session code
I've been doing this in a widget
Sorry if I sound a bit dumb, this is basically my first time touching UE multiplayer
I haven't done this in BP but in C++ while travelling (OpenLevel node in your case) we need to specifically set Game Mode in travel url
No problem
Also make sure you are setting up Blueprint Game mode classes and not C++ ones, if you have those
So another question, does this multiplayer actually work? I mean, right now I have only tested it while launching the game several times on my PC, but will it work if I hand my friend a copy of this and we try to connect?
Ofcourse that's why it's made. You need to either connect via LAN and setup ports or switch the subsystem to use some service such as Steam Subsystem
How would I set it up though steam?
Many online YT tutorials would show you
k Thanks
Ok so, I did not find any way to set the gamemode, and I think It probably has some restrictions towards the authority of the player that can cast to it, i.e. the server
I am probably wrong though
What happens if I change the variables replication?
What is the issue you are facing specifically?
I'm trying to replicate the variable that holds the number of ready players, but failing spectacularly
Failing as in it is not replicating, right? But the game is up and running and the server and client are working properly?
Wats dis?
Yeah
Idk, I think you are looking in wrong place
variables won't replicate by themselves first of all.
Have you declared the variable to be replicated?
Now yes
Does anything else replicates fine?
Idk, this is the only thing I am trying to replicate, but movement replicates fine
Variable is in an instance on server and when you change it's value it's not reflecting on client although you've set it to replicate, right?
It's in a widget
That won't do
Where do I set it?
Yep
Who's setting the variable on widget?
The widget itself
Then there is nothing to replicate
Both client and server have their own instances of widgets
But can't I copy the value between all instances of widgets?
There maybe somewhere you are getting the values that you set for the variable?
What does this variable signify?
Wdym by signify?
What is it used for?
Storing the number of players that pressed the ready button
Do I move it to the player controller?
Store it in GameState that is set in Game Mode Settings but has it's own instance on client and server and then get it from there.
When you'll replicate the variable it will replicated it to all the game states and then you can access it via Get Game State
Ok, so I move the variable to the Game State and set it to Replicated
Gonna try that, thanks!
I mean, do it carefully
I just did that. It is the way.
Thanks!
See widget variable replicating on both server and client
Definitely 🖥️ 💥
Make sure to increment variable on GameState of server via Server RPC or whatever you may and not on client
Widgets dont replicate.
You want the variable to live in a replicated actor (probably GameState in this case) and be set by the server
Yes that's why I said widget variable, I meant variable for use by widget. poor choice of words. sorry
The widget can just get the variable from the gamestate whenever it wants, either tick or binding
then the widgets handled
just mark the variable as replicated on gamestate and set it on the server-side and you're good
Yes that is what I did
I am trying to use Advanced Sessions plugin and setup a dedicated server for steam. When I go to build I get these compilation errors1>J:\UnrealEngine\Engine\Plugins\Online\OnlineSubsystemSteam\Source\Private\OnlineSessionAsyncServerSteam.cpp(307): warning C4996: 'GetBuildIdAsSteamKey': UE4_PROJECT_STEAMGAMEDESC has been renamed to UE_PROJECT_STEAMGAMEDESC. Please update your code to the new API before upgrading to the next release, otherwise your project will no longer compile. 1>J:\UnrealEngine\Engine\Plugins\Online\OnlineSubsystemSteam\Source\Private\OnlineSubsystemSteam.cpp(44): error C2059: syntax error: 'namespace' 1>J:\UnrealEngine\Engine\Plugins\Online\OnlineSubsystemSteam\Source\Private\OnlineSubsystemSteam.cpp(45): error C2143: syntax error: missing ';' before '{' 1>J:\UnrealEngine\Engine\Plugins\Online\OnlineSubsystemSteam\Source\Private\OnlineSubsystemSteam.cpp(45): error C2447: '{': missing function header (old-style formal list?)
I am building in 5.2. Not to sure what is happening.
The first warning simply tells you, that you should be using UE_PROJECT_STEAMGAMEDESC
I saw that but only just realized that it was refering to the Target.cs file...
The error I'm not sure
It's probably a false error because of the depreciated definition I had...
It's happened before.
That's also 2 different files
OnlineSubsystemSteam vs OnlineSessionAsyncServerSteam
But that one also has a define above it that you might not have updated
UE_PROJECT_STEAMSHIPPINGID
I am building now. I will let you know.
Looks like it was an issue with the definition
Hello, I'm looking a way to pass some data to a server I'm player connects to along the request message or something like that. Does anyone have any idea how to do so? I was trying to go through some source code, and found AGameModeBase::Login function which takes FString Options, but I'm not quite sure how I would pass something in there. It seems like there is a lot of code.
Could anyone give me some advice on how to achieve this?
If you're connecting directly, then you pass them in the connection string delimited by ? and using an = between the parameter name you want to use and the value.
So if you're trying to connect to localhost and passthrough a player name and a "character" value it would look like:
127.0.0.1:7777?playername=Jeffrey?character=5
Usually you wouldn't be doing this, but using sessions instead which I believe you can do something similar.
How would I add something to the parameters though?
I didn't find a function for that
You just add more to the string as you need.
Unless you're talking about sessions specifically.... That i'm not sure about but there is supposedly a means to do it.
Yeah, I do understand that you can append values to a string, but what's the place I would do it?
When the client is connecting to the server. I don't think you can do it when playing in editor.
What do you mean? I don't get it. 😅
Just to make it more clear:
What I want is passing the player hero data to a server, which is not just a hero class, but different other things, such as equipped items, level etc. This data is stored on the user computer, i.e. no main server which would contain the data and avoid cheating or something.
The reason why I need to pass these data as soon as possible, instead of making a client RPC call to a PC, which would make an server RPC with all the data, is because I need to use to use it to initialize the PC/PS using it.
Hey @fathom aspen another chapter of desync root motion on client.
Someone smarter than me found the real issue, apprenttly is related when the culldistance closes and reopens a channel.
https://issues.unrealengine.com/issue/UE-119442
Hope epic fix this one or pulls the workaround as a bool.
The client needs to make a connection request to the server at some point. It's when you're making that connection that you pass in options that the game mode's Login function will read from.
In blueprint, you'd use something like the "Open Level" node on the client that is going to be connecting, in which case you pass in the connection string that I mentioned earlier (127.0.0.1:7777?playername=Jeffery?character=5) and then when the server receives the client's connection attempt, the Login function is fired and it reads in the "options" that were passed through on the connection string.
Sessions would work similarly, you should be able to pass through some options when establishing a connection.
Ooh, yeah, I forgot about the Open Level node. The thing is that I'm using Lyra, and it joins a session this way, that's why I wondered how I would actually pass the options.
Are you familiiar with this approach by any chance?
The "Session Entry" may have some means of adding additional data, but I can't seem to add the Common User plugin in 5.2 to be able to see it myself.
Hmmm interesting... good find
Was you going out of relevancy range in your case though?
I mean the only function I know of that changes the active state of RepRootMotion (and it makes sense to be that way), is PreReplication.
Wondering on why would it always set it to false when the ActorChannel gets reopened
I mean literally breakpointing ACharacter::PreReplication and checking what's going in there
I thought the same way, however...
The function signature:
void UCommonSessionSubsystem::JoinSession(APlayerController* JoiningPlayer, UCommonSession_SearchResult* Request)
The session entry definition:
It seems like it's not about options/arguments, but more about a found session instead.
Oh, wait, I didn't see the GetStringSetting method, perhaps that's what I'm looking for...
Apparently it isn't. It is the found session data, such as game mode, ping, map name, players current and max amount etc.
The only data client passes is the LocalPlayer, however, by following the functions chain, I found that at some point the LocalPlayer is not passed anymore, but its UniqueNetId instead.
You'd end up having to change UCommonSessionSubsystem::InternalTravelToSession and anything up to it to pass along additional options.
It eventually calls
PlayerController->ClientTravel(URL, TRAVEL_Absolute);
The URL value would be the same as the string you'd use in an Open Level node.
if the server calls a MyMulticastEvent , so every client should call MyMulticastEvent too independently?
If the actor is replicated and relevant for them all, yes
I was thinking that. And I've never paid attention to the culldistance in our game as the potential trigger.
I'm not very savvy in what the source code does with relevancy, but I'm wondering if when you have some dozens of awake actors, even all being inside the culldistance, they can also close their channel due to lower netpriority of others.
What I don't get, is the reason of being backlogged
Obviously Iris...
Well what I know is ActorChannels can get closed due to several reasons, but obviously not because their Actor has a low net priority. Lower net prio means lower considerability for replication. The ActorChannel shouldn't be closed.
From what I recall of the footage you attached at the time, you were not passing the the default net cull distance, so unless you had a really short one, your issue could be something else 
so just a general question, im making a "2D" platformer, but just using a sprite on a capsule. does anyone know the direction to look for what i need to replicate for updating to the correct direction of the sprite? basically when the player inputs left or right i flip the control rotation and actor direction, so my guess would be, do i need make some dummy variable that is set everytime the player flips left or right to replicate?
I'm spawning a character and the is locally controlled is false on the current client and also for others, what could I be doing wrong?
You possessing it?
yes
When are you checking is locally controlled?
begin play of the actor spawned
I asked in chat gbt and it said this:
Replication: If the node you're referring to is an actor or component that is set to replicate across the network, the "Locally Controlled" property might be false on non-authoritative clients. By default, Unreal Engine only sets the "Locally Controlled" property to true on the authoritative client (server) and false on remote clients. This behavior ensures that remote clients don't modify the replicated data directly.
that's bullshit
BUT
you might be checking too early
print it on tick, does it eventually say yes?
let me check
might be a race condition
note, it'll only be locally controlled on the machine of the player who possesses it
also false
always
I found another way of testing, Im checking the owner if is empty or not
it worked for the behavior I wanted, basically hide actor to the opponent and show after a certain time
So I have an ActorComponent on my AI controller, what the best way to get value forClient UI purpose?
What value?
what does it represent?
How do I wait till all controllers have connected/been spawned in as a pawn to complete tasks in a variety of blueprints?
I have an actor component managing states of the AI, like idle, attack etc and I want to be able to get it and display it on the Player as a widget so on client
I am creating the widget on the Client already link to the player PC that part working well be I can't find a way to get that value specifically
look into giving your AI PlayerStates
That can be a thing, or just put it on the pawn
pawn is replicated
AIController isn't
oh hence broadcast didn't work
I tried to broadcast the value on a Multicast but was nover triggered for client
I will check the PlayerStates, thx a lot!
Why does this code show the widget for both players when it should only effect the player who was in the collision?
This code is within the player
you haven't posted what is triggering the start of that big chain but my guess is you're running that code on all clients
both clients are running that code for both players in their own worlds. So AddToViewport is getting called on both clients, and... adding that widget to the viewport.
Ah yeah sorry
Is there a way to fix this?
don't use a multicast?
or, if that does need to stay a multicast, check if the character is locally controlled before running code that needs to be run only for the owning client.
why does 1 of my repnotify functions have graph properties but the other ones say "graph is not editable"?
Can you show what you mean?
Not sure why it would be doing that, you shouldnt be modifying OnRep functions anyway
why
Because they are auto generated and called automatically, you have no control over what gets passed into them
Let me clarify, you shouldnt be modifying the function signature
You can do whatever you need inside the function, thats fine.
But now if I do it like this the server is always effected, though I would want the character who's in the hitbox to be the one that has the widget displayed not the server every time
that's not what I said to do
I said don't use multicast. Running on the server is not the only option... just change it to be a client RPC instead
So run on owning client
when i spawn my character doesnt get replicated to others
This code does the reverse of what I need it to do, as it's effecting the player who did the confusion spell rather than the one who should be effected
and when i check SIE my char stays in the same place it spawned at
how do i fix
they both are named char0 when selecting debug object
normally it will have debug objects with (client) and (server) on the end why am i not seeing this anymore?
ok net mode was standalone instead of client, i feel dumb now
The 3 types of RPCs:
Client -> Server or "Run On Server" indicating you want the server to execute something.
Server -> Client or "Run On Owning Client" indicating you want the server to communicate something to the owning client of the actor, keeping in mind that you can't send anything via a Server->Client RPC if the actor is not owned by a client. Usually Player Controller, Player State and their controlled pawn, as well as any of the components attached to these actors normally would have a client owner. The code in this RPC will only be executed on the client.
Server -> Multicast or "Run On All" indicating that you want the server to communicate to all clients that see this actor as relevant, and each client will execute the code themselves.
If you only want the player that is performing the overlap to display a widget on an overlap, then you likely want to check if the overlapping actor is "locally controlled" and then create and show the widget. No need for any RPCs. If you want it to be server authoritative, then somewhere on your overlap you'd need to use a "Has Authority" node and use the "Authority" branch, and then have a Server->Client RPC on the character to then display the widget for the owning player, or, you'd use an OnRep variable like a boolean called "IsConfused" and when changed the OnRep will be called in which case you'd do the same thing and check if the actor is locally controlled and IsConfused is true, and display the widget if so.
Thanks man
It worked like a charm thx a lot for the help!
im doing set w/ notify on the server for a bool but it fires only on the server
Did you check the replication condition
its repnotify
The condition of replication, like replicate to all or?
none
Ok, so what class is it?
?
The blueprint you set the replication variable.
its character
Is it replicated?
yea
Always relevant?
no
Try this flag
still prints only on server
Where did you print it out?
2nd image
in onrep function
might be confusing but make sure you dont confuse "use controller rot yaw" and "use controller rotation yaw"
Ah, okay. Maybe try to set the break point to see if it is really triggered on client?
Looks good for me though.
ok
yea its not triggered on client only their server instances
repnotifys can only be called in server right?
Nope, it should be on both sides.
set w/ notify should work if u call it from client too?
No, only set the variable on server will replicate to the clients means OnRep get called because it replicated.
And, does you change the value actually?
If the value not changed, it won't trigger.
If it was false and you set it false, OnRep not called.
either way it is this should work
but it just does not want to fire on client
by the way im doing this on BeginPlay
Ah that's it.
Maybe the client side didn't spawn at that time.
Try to make a delay?
😆
ill try it again
Only OnRep not working?
yea
That's very weird.
ig it doesnt matter i just found i can set it in properties, im still getting a bug with flicking though
Hey there!
Can someone help me out with Actor component replication?
I've set up an ActorComponent that has a function that periodically calls a Server RPC.
Said Server RPC will then call a Client RPC which I would expect to be executed on the client that owns the Owner actor of the component.
More about the setup:
The ActorComponent is set to be replicated in its ctor via SetIsReplicatedByDefault(true);
The ActorComponent is instantiated at runtime, on server-side in the PlayerController's BeginPlay() function. It's registered properly.
The ActorComponent is set to replicate so the PlayerController on client-side will have the component set.
I've checked ownership and it seems to be fine, that is:
Client's player controller is set as owner of the ActorComponent.
The problem I'm facing is that when calling "ClientUpdateWorldTime" it seems that its called on server-side whereas it should be routed to the client.
Attached a screenshot for reference:
Nevermind that. Turns out I was an idiot and incorrectly called the "_Implementation" variation of my RPC function. Once I called the correct function variaton (one without _Implementation at the end) everything worked nicely. Lesson to be learned, don't be a fool like me 😄
how do you not be a fool lol
I have a question regarding sessions: Is it possible to connect a client to two (or more) dedicated servers at the same time?
Assuming the servers would run the same level, and let's say server A has some actors F, G, H, and server B has some actors R, S, T. Could I connect a client C to servers A and B so all actors (F, G, H, R, S, T) are replicated on the client C?
Not out of the box no
It would require heavy modifications to the engine.
there is usually a way simpler solution, what is your goal here?
Is updating a value over network every 0.03 seconds a terrible idea? Even if it's just 3 floats?
It's for a fast firing gun, aiming target
target as in vector or target as in actor?
if I have a replicated property that's a uobject and on the client it was modified and I want the client's version to be the same as the server aka correct it, how'd I generally do that
if I send the uobject in an rpc from the server to the client would that do anything?
Vector
So like just 3 values. Not that much but I'm more concerned about frequency not size
unreliable server RPC on Tick is fine
as long as its unreliable, you're good
reliable doesn't make sense for something running on that frequency
because if the RPC needs to be resent, data for it is now already way out of date
So sending individual shots (as well as "start fire" and "stop fire" for fast) for slow weapons using reliable, and aiming updates for fast firing using unreliable
I see
yes
well, your target vector doersn't really depend on slow or fast firing weapons
and you might want to turn the character aiming, even if not firing, towards the target so other clients can see that too
I just don't see a reason to send aiming updates if the fire rate is less that aiming send rate. My "single shot" is really also just a vector.
So that way, if a weapon only makes 10 shots per second, I'd be sending ~30 aiming updates per second (once every two ticks)
While with single shots I'd be sending 10. But single shots must be reliable, so there's that
Network optimization looks pretty deep
I really made this "start fire" "stop fire" thing cause I don't know if I'll ever have guns so fast they fire multiple times per frame 🤪
Hey hey, anyone know which FArchive is used for net serialization?
need to check how an operator is implemented
so just a general question, im making a "2D" platformer, but just using a sprite on a capsule. does anyone know the direction to look for what i need to replicate for updating to the correct direction of the sprite? basically when the player inputs left or right i flip the control rotation and actor direction, so my guess would be, do i need make some dummy variable that is set everytime the player flips left or right to replicate?
I have multiple solar systems in a persistent universe, similar to Eve Online, across multiple dedicated servers. But rather than just piloting only one ship like in Eve, it's more of an RTS, so theoretically players can have ships in multiple solar systems at the same time.
As I see it there are only two options here:
(A) Whenever the player switches from controlling a unit in solar system X to a unit in solar system Y, connect to a different server.
(B) Connect to multiple servers at the same time.
Option (A) seems rather expensive in terms of network traffic if you swap often between solar systems, and constant load times could be annoying, so I would prefer somehow figuring out how to do (B).
there are distrubuted dedicated server solutions out there
where servers also comunicate with each other
basically, multiple servers running the same world scenario
If I understand it correctly, it would mean implementing server-to-server replication right? Or does such a feature/plugin exist already?
Oh was it SpatialOS?
that sounds familiar
it was originally made for MMORPGs i think, so it shouldn't have that transition problem
but i remember very little, i just watched a presentation and it was years ago
if they are still around and compatible with 5.2 its a good sign
Yeah I remember reading about it quite a long time ago, but haven't kept up to date with it. I'll check it out, thanks for your help! 🙂
does someone know why theres this weird little jitter for the client?
are you replicating your capsule or skeletal mesh?
they can cause jitter when replicated
oh yeah just turned it off and that fixed it, thats weird
aside from that, you might have different movement speed on server and clients
not really, i have the same thing- the only thing i added to this project was an ability to dash and roll and neither change the speed- i originally had an issue with my roll and saw this jitter on input and couldnt tell why
blueprints?
quick question, i want to apply velocity to te character here when i roll, would i do it on netmulticast or only server
cpp
some stuff in bp
like the roll is completely bp
atm atleast
its a struct containing predicted movement data
so, odds are that you can't dash and roll predictively, which then causes corrections
so is this like client side prediction?
the idea is you send your FSavedMoves to the server
server uses those to move you/calculate your position
then it RPCs your position on server back to you
after that, you reapply all your saved moves after the time server sent an update to the server provided location
and then if there is more then iirc 3 UU difference, correction happens
with no data that you're rolling in FSavedMove payload, that won't work
i see, i sadly dont understand much of this so i shall look into unreal documentation for more deeper explanation. Thanks for helping out though! i appreciate the information and the help : )
search the pins on the channel
here
there is probably some good CMC stuff in them
oh okay i shall do that then
Hi again, I've tried the solution advised earlier and now it almost works. So I moved the variable to the Game State and made an update event, which will be called every time I change the value. Issue is, this only works when I press the button on the server, then it replicates the changes towards all the clients and it works; However, when I press the button on the client, it does not replicate at all, and it seems like the R_Ready_S (Execute on server) event does not fire at all. Does anybody know what I am doing wrong? Sorry for possibly being a dumbass, a have little to none experience with networking
This is my Game State Blueprint
And this is my Widget Blueprint
should instantiation of vfx be handled on backend or client side?
Client side
im a noob aswell, but does client run remote or authority on ur code?
Wdym?
have u ran the code in game and seen what wire executes when u press on client?
u said that run on server most likely doesnt execute
I have seen that using the print strings, and it showed that the run on server event does not even trigger
another great debugging tool is to run the game and then u see wires light up in real time
but i think ur problem is that client cannot run the "run on server" since its not the server or owning client
so ur Switch has authority node doesnt work
Why would you have the switch has authority there though?
well the "remote" doesnt work
I dont understand
You are either way running a server event on remote players
This compendium is meant to give you a good start into multiplayer programming for Unreal Engine.
Just get rid of the switch has auth and run the server event that runs the multicast event. Pass the val from the server event to the multicast event?
Clients can't run server events on GameState as they don't own it
the only thing a client can send data through is a thing they own, usually PlayerController or Pawn
Or PlayerState I think
How would I do it? Move the entire thing to player controller?
Or PlayerState, Ready should be a variable on PlayerState anyway
The State of the Player is that they are Ready
If i want to have classic multiplayer where players need to wait server for each action (so they feel ping and dont need to predict anything), is it enough to just send RPC from client and then server execute it and clients just replicate all data or i need something more complex?
That's the ticket
okay
The only way clients can send the server things is through a run on server event
from there, you should default to replicated variables with repnotify if you want to run code clientside when the variable changes.
I'm not quite sure I understand the difference between AutonomousProxy and SimulatedProxy, specifically for normal actors, not characters with their character movement component. If an actor is owned by a pawn, does that make that actor's role also AutonomousProxy, like the pawn? And how does that change anything in how it's movement is replicated, for instance?
K, so I've moved the entire thing to the player controller. but this time nothing work at all, even when I call the event from the server
show your code
multicast doesn't mean shit in a playercontroller
Do I move it to the player state then?
Widget:
Input -> send a bool to serverside playercontroller or playerstate through a run on server event
PC/PS:
recieve bool serverside -> set bIsReady on Playerstate (repnotify)
Repnotify
Do whatever you want with the new bIsReady -> Has Authority? -> call CheckIfAllPlayersAreReady wherever that lives (Gamemode probably?).
don't multicast ANYTHING
Learn it, love it
k, Thanks!
Well I found out some news on UDN today for anyone who was interested in the network prediction plugin: it's confirmed dead. There's going to be a new general purpose network prediction implementation in the engine (timeframe tbd I guess)
So repnotify will automatically call the function that was created?
Whenever the variable is updated over the network, yeah.
I think I did everything you said?
Ight, Imma gonna go take a nap, pls ping me
That's not really it
you're making things way more complicated than they have to be
The variable for if you're ready or not should live in your PlayerState, and should be replicated with repnotify
so instead of your flipflop, READ that variable and send its opposite (not boolean)
It's your gamestate's job to check if all ready
not the playerstate
the playerstate just tells the gamestate to check (since its ready state just changed)
I"m using some custom MatchStates that i've declared like below - and when I log/printstring these (after setting them in GameMode) they're coming through the gamestate as 'None' . What am I doing wrong?
UE_LOG(LogVIGame, Log, TEXT("%s => MATCH STATE CHANGED => %s"), NETMODE_WORLD, *MatchState.ToString());
namespace MatchState
{
const FName Default;
const FName StageIntro;
const FName Lobby;
.....
}```
this is defined in my projects GameMode (NOT BASE)
Hey does the player state persist when switching game modes?
And if not, what class can be used that persists for the player between maps and matches?
GameInstance is the only thing that persists by default. (And the GI Subsystem)
Any other persistent thing needs to be set up manually
Thanks guys
You presumably want saving and loading to be a thing, that can be an option too
save -> change map -> load
what can cause this error on my server logs?
LogNetPlayerMovement: Warning: ServerMove: TimeStamp expired: 32.698910, CurrentTimeStamp:
well how long before we should restart them?
well if you've ever played any MMO you'd know that they have a weekly maintenance period -w hich is them restarting (and other things)
i would suggest at least that.
Hey y’all! I’ve been having a lot of trouble replicating an actor change within my game! I have capture points set up, and they are supposed to change color once a player captures them, however the color only changes on the server. I tried server to multicasting the changes, and that did not work. After more research I believe the rpcs are getting dropped because the capture points are just blue print actors that I have thrown into the scene, meaning that they are unowned, and in turn dont have a net connection. I tried to set the owner using SetOwner() to fix this issue, but it didn’t work. I set the owner to both the first player controller and the game mode, to no avail. I even tried having game mode spawn them in but that didn’t work either. If anyone can give me some tips or advice for getting unowned actors to have a net connection so that they replicate, that would be extremely appreciated!!
Stateful things should be happening through replicated variables set up with Rep Notify. When you change the value on the server and the value replicates, the OnRep function will execute on the clients which you can then use to do anything visual you want.
Mutlicasts can work as well, but they're a fire once and forget, so if the actor goes out of relevancy for a client, the client won't receive the change.
You do not need to use ownership of these objects unless you want the clients to be able to send an RPC to the server through them (which you shouldn't need to in your situation). All that should be required is that the actor is marked as replicated and any variables you want to use to convey data about the actor to clients are marked as replicated.
I see, so currently I have the entire BP set to replicate, however I want specifically the UI and the radial ring around it to change color once a character captures it. I should set both of those subcomponents to replicate as well and that should be it? Would RepNotifys work even though the actor has no NetConnection?
Placed actors marked as replicated will end up having a net connection.
Your replicated variables should be specific about the state of the actor. You don't necessarily want to set components to replicated unless you know for sure they have values that actually can be replicated. You probably have some sort of variable keeping track of who has the object captured, like an enumerator that has three states: Uncaptured, CapturedRed and CapturedBlue, then you'd definitely want to use that one particular value to be replicated and set as with Notify. The OnRep can then use the replicated value and make the required to changes on clients without having to worry about marking the components as replicated.
Ahh I see okay, and I assume I would need to set the changed variable in GetLifeTimeReplicatedComponents as well?
Got it, I will try this out, thank you!
Quick question, losing my mind a little bit here. I'm trying to have my clients be able to click a button that spawns a tile. I know I have something wrong here but I don't know how to fix it. The reids video said you have to own an actor to run an event on the server on the actor, but I don't believe I'm implementing that correctly:
for reference, it's calling this function on the gamestate:
Don't cross execution lines when dealing with network related stuff. The input would be client side, so only the client knows about that particular cast value, the server wouldn't.
Additionally, you cannot call Client->Server RPCs on the gamestate or any other non-client owned actor. You must RPC through a replicated client owned actor (like their controller, character or playerstate, or any of their components that are replicated) then when running on the server you can have the server call the gamestate or the actor that you want to interact with.
You also can't change ownership on the client. It must be changed by the server if it is a replicated actor.
So if the actor is a button that has a click function, how would I run the logic through the player controller? Would I click on the button, have it go to the player controller, then to the gamestate?
In other words how can I have the client click on a button to call a multicast
In their character you'd likely have some kind of interaction event that you would trigger by key press or mouse input. You'd need to do some kind of trace or know which actor it is that you want to interact with.
You then RPC to the server on the player's character with an "Actor" input on the RPC to allow the client to tell the server which actor they want to interact with.
When running on the server, you can validate that the player is close enough to complete the interaction, and if so, trigger any additional logic that you want to happen as you're now running on the server. A common thing to do is create an interface and implement it in any interactable actors you may have, so then you can pass in the actor reference from the RPC through that interface, and trigger the implemented interface in the actor. Through the interface you're now executing on the server and are running code on the actor. You can now multicast from the actor or change any replicated values as you're running on the server.
With the button sprite, I'm not exactly sure how it needs to work, but you'd have to send it back to the interacting character/controller and do the client->server RPC from there.
that's what I was thinking. it's a 2D card games with players just clicking on the button, so I figured I might have to go from the button to the player controller, then to the gamestate, but when I used get player controller it doesn't ever get the client's controller so I'm not sure how to make that work
Well what is that button? is it a widget?
your advice is always on point and you always explain things so well. thanks for all the help you give here because I always learn something even when you’re helping someone else. 👍
Glad to help 🙂
it's an actor with a sprite
Ok, so then the On Clicked event I believe only ever executes on the client - you can test this yourself if you put a print string immediately after the event and try clicking on it....
You'd likely only see "Client: Hello" and not see anything like "Server: Hello" right?
The only time you might see "Server: Hello" is if you happen to be running a listen server and are clicking the button on the listen server's window.
That's looking better.
Are you sure about placed actors marked as replicated having a net connection? I tried the rep notify and it seems like the function that is called on rep notify is not being called even though the variable changes. I have for sure set the object to be "replicated" within its blueprint, do I have to do anything special in the Cpp file? Because as it is now the obejct still does not have a net connection
Absolutely. Are you sure you're changing the value on the server and have appropriately set up the property to call the OnRep and have updated GetLifetimeReplicatedProps with the DOREPLIFETIME_NOTIFY() for that property? (Assuming you're setting up the variable in C++)
oh I see, I wasnt aware of the DOREPLIFETIME_NOTIFY() property. I was just replicating the variable that changed using DOREPLIFETIME()
and how can I make sure that I am changing the value on the server?
That's something you'd need to know - like, if you're doing something like an overlap, checking if there's authority or it is a server when the overlap happens etc.
When you have that gated off, then whatever function calls after that should be executing on the server.
Same if you started the logic from a Client->Server RPC, you know from the RPC you'd likely be running on the server, but unless it's a player owned actor, the RPC wouldn't fire.
I see, so once the point is "Captured" I should call a ServerRPC which changes the variable?
And I call this RPC within the captre point object itself
No for two reasons:
- You don't want clients telling the server they captured the point, as then players could call that RPC whenever they want.
- You can't call Client->Server RPCs on non-client owned actors.
The server should already know when a player is capturing, and when they have successfully captured the point. Again, good example would be an overlap where you would have it check if the server detected the overlap, and if so, have some kind of timer or what have you, and when the timer expires, the server then knows it was captured.
When the server knows the capture was successful, that's when you'd set the variable.
Hey gys, question. Do Rep Notify condition on blueprint works? Eg SkipOwner, etc
You don't need client tile request
That's to run on client from server
Button -> run on server event
Run on server event on the player controller? I could’ve sworn I tried that, but I’ll try it again, thanks!
Ok it work, just tested
hello everyone.I am facing an issue.I am making a multiplayer game for android where the max people in room is 4.There is no point in going dedicated server.EOS is having all the library issues and crashing on android.Can anyone tell what is the best solution for android for 4 people.Is it relay or listen server.Any hint on how to do that??
OnEndPlay should call on the client aswell, when an Actor has been destroyed on the server, correct?
Anyone having experience **multiplayer with ** chaos vehicles?
- Jitters on server authoritative simulation
- Out of sync on client authoritative simulation
How should I approach this?
I have a hypothetical solution
Please correct me if I'm wrong
- Use client authoritative simulation , and let physics handle state of my vehicle on server and other clients (activate vehicle movement component on owning client only).
- Or use server authoritative simulation and try to control jitters somehow
Any headings or tips are appreciated
So OnRepNotify can have a pointer to the Variable being replicated. How can we expose it the same way in Blueprint RepNotify?
You can't BP doesn't support the "Last Value" param
😢 @thin stratus Got u, thanks
i thought onrep functions could have a parameter though?
oh is that cpp only?
Yop
Just make a BlueprintImplemetableEvent like K2_OnRep_OverlappingWeapon(AWeapon* LastWeapon) that gets called from the onrep
Guys i am making a listen server mode game.I am getting public ip of the host using whatismyip.org website.But when i use open ip command,i am not able to connect.Can i know how to connect??
it is working locally but not working when we are on diff networks and using public ip address
Guys I'm making a game mode where my gamemode will spawn some players and when I meet a minimum number of players the game will start but I don't know whether to possessing in gamemode or call a function to my pawn which is the best
You just spawn the player pawns when the player controllers reach a certain numbers in game mode and posses it after spawning. Is the problem that you don't know when the player reaches the number?
Having told you, my game needs a minimum of 2 players, that is, 2 player controllers that I know using the postLogin function, I save this in an array and check its size, if this array contains 2 elements, that is, my 2 player controllers, I will generate 2 pawn with their statistics from which I will get another array of the stored positions of other actors. The question is if I do the possessing within the gameMode or is there another way to do it
It's just that sometimes I'm having problems synchronizing the positions when my game starts between the players, so it usually happens to me like jerks between them
Ah, ok. I usually possessing it in game mode and it is also the only way to possess it on server side. Gamemode is fine to possess in my opinion.
I have a question, what is the use of the OnPossessed event of the pawn then?
Does this run every time a pawn is owned?
Hello, i am trying to replicate this function, when i use the custom nodes i made so it work on multiplayer i get a total different result
How would you go about creating a password protected session? I'm seeing 2 ways right now both equally bad
-Add the password to a session settings and check before joining on a client - fast but prone to hacking around
-Join the server and check on pre-login - this will be a pain in the ass because you have to travel before getting kicked
why not check on both? You'd check it on client (to save you from having to connect to the session first), if all good, client tries to connect. Then you'd check it the server when the player connects again (cz client should never be trusted), and if the pw doesnt match you can still kick.
yeah but that's still prone to hacking since the client can just read the password on his machine
I'm reading up on one way encryption and it seems like a good way to go
I have MMO survival game and it is open world and works with dedicated server. It works! But I want to create one dungeon (separate level) what could be best way to do it?
K, so I have redone my code as advised earlier, however now it only works when I press the button from the server, and for some reason not when I execute it on client, and I have no idea why
I have a weapon sway component I made in cpp. I tested it in standalone mode and everything seems to work smoothly. However, in multiplayer, even when playing as listen server (so when my instance of the game has authority, just to make sure it's not some weird replication issue), it looks very stuttery. I added a video to show what I mean:
Any idea what may be causing this?
hello there, new to multiplayer here, is OnRep_Notify intended to not fire before joining a server or am I doing something wrong?
Update: after debugging I have managed to locate that for some reason even though I set the event as Run On Server the "has authority" still declines
I've been at it for a week
Hello,
out of curiousity and to better my code, let's say I have a Manager class that manages a bunch of Trees, if I know that a function in the Tree is 100% only going to be called from the authority Manager ie from a server RPC in the Manager, I shouldn't need to make that Tree function an RPC right?
I tend to lean towards the habit of making it a server RPC even though I know it'll be called from a server referenced context
Hello, I have a small and stupid question, is the replication working well in the construction script?
No
You don't need to make it an RPC, but for safety, you can add a HasAuthority check to the function
If HasAuthority == false -> return
isn't that still the same as my paranoia making it an RPC? 😂
I guess it's always best to be safe though
Setting all the server functions as RPC is a waste of time and maybe impact the performance or compile time 🤔
Server functions inside the same actors aren't all RPCs but what I'm refering to mostly is when a different actor with server authority is calling a function of another actor from a server reference
I mean, it technically doesn't need to be an RPC
unless it could be used on its own somewhere else and even then it's better I think to just create a function then an RPC to call that function if you need it
?
Widgets don't support replication like actors
Yeah Widgets are only present on the client
So Run on server events do not work?
Yes you would need to use a different actor to call RPCs
You just making it more complicated for yourself
for example the player controller
true, it probably wouldn't even have any real impact on anything
So LobbyController, make a server RPC there
and make the widget button call that from a reference to the controller
Sometimes I just add a comment like Server Only to remind myself that this function should only be called by the server, No need to RPC and HasAuthority check
Any ideas about this?
That's cool yeah, what I actually do is include it in the function name, I have a like a naming convention where if it's an RPC I preface it with SV_FunctionName client CL_, multicast "ALL_" and if it's a function I know is only called by the server I add an F, for ex "SVF_FunctioName"
You meant the delayed gun movement?
how can i replicate this node?
Make sure movement replication is disabled after you attach the weapon to the player
But I basically do that, no?
You're calling the local SetReady
because widgets are on the client only that RPC ToggleReady is just local
Try changing OnClicked of the button to get the controller then call RetryOnServer
or make SetReady a ServerRPC
you'll get the call
It is, I tried disabling replication for the whole weapon completely, and the result is still the same... I also messed around with the tick order, tried every option there but again, no change
Do you actually need that delayed movement handled by the server?
The standard way of naming them is different
https://docs.unrealengine.com/4.27/en-US/InteractiveExperiences/Networking/Actors/RPCs/
ServerMyFunction
MulticastMyFunction
ClientMyFunction
Use a multicast to tell all the clients to run this node
Make sure the weapon is not colliding with anything as well, you can disable the collision when the player holding it
Collision is also disabled as soon as the player picks it up
Is collision disabled for the server and clients?
It worked fine on 1 client but didn't work with 2
Are you sure your code isn't impacting the gun of another player?
and also, do you need that swaying to be handled by the server? if it's only for the player's visuals, you should just do that locally
it works, thanks
The pickup is handled on the server then multicasted to everyone - so collision is disabled on all clients as well as server. But I even tried with the gun actor itself not being replicated at all, and it does the same
That's more or less what I want, to handle it just locally, but idk how
The gun actor should be replicated, just attach it on the server side, you don't need the multicast
But you still need a multicast to tell everyone to disable the collision
Or in C++ you can override
void OnRep_AttachmentReplication()
// Called every frame
void UEquipmentSwayComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
if (!OwnerAttachedSlot || OwnerAttachedSlot->SlotType != EEquipmentSlotType::Hand || GetOwnerRole() == ENetRole::ROLE_Authority)
{
return;
}
FVector DeltaLocation = LastOwnerWorldLocation - OwnerAttachedSlot->GetComponentLocation();
FVector LastOwnerLocalLocation = EquipmentOwner->GetRootComponent()->GetComponentTransform().InverseTransformPosition(LastOwnerWorldLocation);
FVector DeltaLocationLocal = EquipmentOwner->GetTransform().InverseTransformVector(DeltaLocation);
FVector FinalVector = DeltaLocationLocal + StraightenStrength * -EquipmentOwner->GetRootComponent()->GetRelativeLocation();
FVector NewLoc = EquipmentOwner->GetRootComponent()->GetRelativeLocation() + FinalVector;
EquipmentOwner->GetRootComponent()->SetRelativeLocation(NewLoc);
LastOwnerWorldLocation = OwnerAttachedSlot->GetComponentLocation(); // Update after we applied our changes only
}
This is my code for the sway component in case it helps - I added the authority check just now to check if it helps
Testing it now again in standalone mode also shows some lag, but it still seems way worse when I play with >1 players... I also noticed that if the final vector is just DeltaLocationLocal, then there doesn't seem to be any lag (though that way I also don't really get the behavior I'm going for) neither when playing standalone or mp
Only enable the component tick for the local player
Something like this in the player character class
void APlayerCharacter::OnRep_Controller()
{
Super::OnRep_Controller();
if (Controller && Controller->IsLocalController())
{
MyComponent->SetComponentTickEnabled(true);
}
}
^
Is there no way to do that from the gun itself? Since it's a component on the gun not the character
You could check its owner
you're attaching it to the character so the owner of that component would be the character
chain checks from that
the character (Pawn) has a check if it's locally controlled as well
This is the result I get if I don't add the StraightenVector from my above code - it seems to have no lag at all, even when playing as client with 2 players. It seems the jittering is caused by that other vector after all, and there's just something that makes it worse when in MP, but it's still there in standalone
Is there any reason I have to do it when the controller is replicated? From what I understand, this happens very often, 100 times per second is the default I think, no?
That's a Rep Notify replication function it'll only trigger when the value gets changed
That wouldn't work really seeing that the gun gets attached while in gameplay
I mean a suggestion would be to have a Multicast after you equip the gun, you can call sounds effects there for equipping and also handle the tick, check if it's attached to a local character, etc
I already have a multicast that's called upon equiping the gun, I can add that there. Thanks for the suggestion!
What do you mean by state change?
You should defo read Cedric's Compendium haha
that's what got me started into networking in UE
I am actually! This one, right?
https://cedric-neukirchen.net/docs/category/multiplayer-network-compendium/
This compendium is meant to give you a good start into multiplayer programming for Unreal Engine.
Didn't even notice it was you @thin stratus , your docs really helped me!
Even though I still don't have such a good grasp on some networking features 😅
But in this particular case, can you give me an example of what you mean by state change?
To try and explain it better:
OnRep (Rep Notify) is triggered whenever a value is changed, so players who were in the server will get it and players who join afterward will get notified as well. So anything which is classified as a State should be a RepNotify, for example Equipped gun, eeehm Hat, for example if you can apply paints on your body, etc
Multicast is only triggered when the call happens (somewhat), so it is more aimed towards things which are relevent to current players in that current time, for example sound effects on equipping, gunshot particle effects, etc
(To my current understanding and experience of course)
Guys anyone implement NAT PUNCH THROUGH for listen server in unreal engine
I usually take an explosive Barrel as an example. When you destroy the barrel you want to:
- Play a Sound
- One Time Explosion VFX
- Changed the Mesh to a destroyed one
- Turn a little infinite fire VFX on that burns in the broken Mesh
Part of that is State, part of that is one-time actions.
MULTICAST:
- Play a Sound
- One Time Explosion VFX
STATE/RepNotify/OnRep:
- Change the Mesh to a destroyed one
- Turn a little infinite fire VFX on that burns in the broken Mesh
You can argue that some of that can be predicted ,etc. but that's not the point of the example
I have an enum stored in player start and I want to set the same enum value in player states of the players that player start is used to spawn. How can I do so?
Are you manually doing the Spawn code or are you using the GameMode?
Probably not, as most users use existing services like Steam
But maybe someone knows
Overriding the chooseplayerstart function in BP
i am making an android game in ue4
well... 😂 that's definitely a better way of explaining it than mine, great explanation
Is that function Const?
EOS is crashing on android always
(i don't know from the top of my head)
so trying to implement it.
It doesn't seem so, otherwise editor would give compiler error, right?
Const would mean you can't set any state in it
If it's not const, then you should have access to the Player that is supposed spawn or?
It does allow to set tho. Just that Idk how to go about doing it.
Probably in form of a Controller pointer
Problem is player controller is on server
Relatively sure the function has an input of AController Player
Yeah that's what I thought, that should work
But it seems that it doesn't trigger for client