#multiplayer
1 messages · Page 160 of 1
I understand, but if there are so many bad tutorials that means Epic didn't make their job properly at teaching their engine / their documentation isn't good enough or well presented engouh, and that's really sad 😦
yeah the epic Mass video tutorial mixes up one specific thing iirc (mostly terminology)
that's one reason video tutorials can suck: editing them to fix mistakes is almost infeasible
I know that's why I'm saying that they need to do something about it
¯_(ツ)_/¯
we are not their business model
not really a priority for them
But this guy isn't doing stuff about unreal 🤔
yeah, I said that
yeah and that's stupid
it's a great channel for how to approach gamedev problems in general
that's about real world examples and experience
trying to imagine what the video content of my unreal channel would be...
"yo what's up guys, it's ya boy Megafunk here with another 4 hour stream of me beating third party ecs libraries into the engine with my clenched fists while screaming "
I don't think I'm a good measure of whats "sensible" I guess... If I made examples of how to make a complete game feature it would probably be laced with "this won't scale to 100 of these ever, be warned"
I think the best approach would be to make series about a specific actor. Like make a full series about the gamemode and all its methods and how to use them. So instead of having a 4 hour video, you divide that into small videos and you put in a playlist to create a series.
Then do another series about GameState, another one about PlayerController, widgets, etc...
So people get the full things available for each class
and understand how ot use those properly
I think it has to have some context, because just going through one actor in isolation seems really rote
I think it could be some "let's make a modern unreal shootergame" while talking about how the different parts of the framework relate and what their limits are etc
there's just too much dumb trivia
I think it would be interesting to show like, an example of a BROKEN project and how to fix it etc to show people how a more experience unreal user actually pushes buttons to reason about problems
The issue with that is people always start tutorials series but stop before episode 10 somehow, instead of going all the way in depth and reach episode 99 and 100
That could work for advanced users but not for beginners, because as a beginner it would melt my brain to start the video and already 13500 nodes on the screen
To me it's better to see someone do things step by step and follow and understand by doing the same, then fixing an existing code
But that would be a nice idea for a separate series called "Fix my Game" or something like that
like intentionally making a mistake and showing "here's what you can try to see what's happening"
But sometimes people code something in a certain way and it doesn't create a bug or a carsh or an unintended behaviour, however there's a better way to do that thing (Like the example above with the tutorial guy creating an array called "AllPCs" to save all the controllers of joined players but Siliex taught me that there's a method already doing that in the gamemode 😄
stuff like that is better off as like, a blog post
like Wizardcells's page has all kinds of things like that
people don't like reading, me included. I like to watch videos to learn better
perhaps some kind of auto reader browser extension would help make it easier
you are missing out if you are ignoring unreal blog posts, especially the ones pinned in here
(not that you said you are)
all of the experts here seems to read a lot tho and probably didn't touch a handful of videos
a video that hand hold you to a complete game is probably non existence
I'm not looking for a video to hold me to a complete game, I'm looking for videos that explain to me things in the engine in depth and how to properly use those. Then with all of these tutorials I can create any game I want with the proper knowledge I learn from those videos
"I'm looking for videos that explain to me things in the engine in depth and how to properly use those"
This is kinda broad
gotta be more specific
to make a working game, you probably can just start with knowing how to use variables, functions, event dispatcher, blueprint coms, references, structs, arrays, etc
The rest is looking at sample project
then reading for advance stuff
I'm learning too, all I can say is I have to unlearn soo many things from youtube
there are still like 1% videos that helped me but the rest are garbage tbh and because they want to make money with views not show you the proper way which take a lot of time
I gave an example above about the gamemode and the "Get Num Player Controlers"
hmm wat about it?
I don't think it has to do with money directly, I think it has more about learning it the wrong way from other people and they want to share their knowledge to others without knowing that it's the bad way of doing that thing. Because most of those youtubers can't make a living out of their videos because of the amount of people watching is so low.
I didn't know that method existed and the guy I followed on youtube for his tutorial saved player controllers in an array when the player joins, and removes it from the array when the player leaves. So neither him or I knwed about that method because I never saw someone showing it or talking about it
what ever the opinion on them, I can only say that you can avoid most of videos in youtube. Especially multiplayer one.
Just read and watch 1 - 2 videos from the pinned section
Which goes back to reading being the best source >_>
U just need to open game mode and read what's available ot you
it's all written
I think there's only 1 perso who did something as close as I want, is Mathew Wadstein where he makes 1 video per node where he explains to you briefly what it is and he shows you an example of how to use it.
there are like 10 k lines, no one will go to every single one
but u just open the source code
u can read tens of function in under a min and get the general idea
can't wait for people to make a video that goes over them which probably would never happend
Or at least make a nice documentation, and I hope I can do that one day but right now my knowledge is weak 😬
so when I get better I hope I can do that
the source code is a nice documentation. It tells what the function return/do
can't be more helpful than it is
I know this has been discussed in the past but It still bugs me, which is character movement on a moving base. So moving platforms, vehicles, etc.
I know nobody knows an easy solution without some prediction logic, but does anyone have any ideas for how to fake it? I just want to make a 4 player coop pirate game. There has to be a way to fake it whether that be some sort of way to disable replication and then just sync it back when players leave the boat or something. I don't need a absolutely perfect replicated ship because players are not fighting each other. I need smooth movement and jumping but it always feels off.
Anyways, if anyone has some fun hacky ideas, I'm all ears.
I have no idea if it would work/help but the other day someone was having issues with the clients on moving platform jumping and getting thrown around and the next day I saw in the UCharacterMovementComponent there was a bServerAcceptClientAuthoritativePosition which " If true, and server does not detect client position error, server will copy the client movement location/velocity/etc after simulating the move. This can be useful for short bursts of movement that are difficult to sync over the network....". I thought that could maybe help but there was no follow up and I didn't try in my project aha. The stuff around it was also related so maybe check that out.
Thanks. I did play around with that and it helps a lot. It helps with the teleporting corrections from the server when jumping, etc. But there are still some issues with jumping while on board a moving object. I was just using a simple moving platform that goes from point A to B back and forth and you can't really jump in the direction that the platform is moving. It's like the velocity or momentum or whatever is fighting you. I mean that's probably realistic just like real life but it's not a good feeling in a video game.
I tried checking and unchecking the impart velocity options but nothing changed it. So a real world example would be if you were standing on top of a moving vehicle such as a train, and you try to jump forward while it's going forward, You can't make any progress 🤣
Wondering if anyone knows of any information on server meshing with UE games (for large populations). I know there's a couple of examples of big games that use it, however they consider it proprietary information so it's not publicly available. Is there anything that is available for us ordinary developers?
So I am trying to clean up my game mode and I now have a struct:
FUGAGolfer() which holds the Controller*, Character*, Status in current level; stuff I use a lot in the game mode.
But I thought I remembered reading that there was an issue with pointers in structs for the garbage collection. Anyone know if I am imagining? In the setting functions for the pointer members I just subscribe to their OnDestroyed() delegate and from there clear the pointers. Is this neccesary and ok to handle this way?
As long as you mark them as UPROPERTY it should be fine
The UObject pointers in your struct that is
I found where I thought I read and it said: "By marking a USTRUCT or USTRUCT array as UPROPERTY() and marking any UObject / AActor members as UPROPERTY(), you are protected from dangling pointer crashes" .... "However you must also clear ustructs you no longer need if they have pointers to UObjects if you ever want GC to be able garbage collect those UObjects." so I thought this meant UPROPERTY() wouldn't be sufficient
(Source: https://unreal.gg-labs.com/wiki-archives/macros-and-data-types/structs-ustructs-theyre-awesome )
You can mark them as weakptr fwiw if you just want to hold a pointer but not stop them from GC
You still need to remove the struct from your array though
So the callback for that part is probably needed
Oki I think I understand. I always consider using weak pointer but then second guess myself and don't do it haha
Ultimately in this case it's fine to not use weakptr cause you will clean up the array entry via OnDestroyed anyway I guess.
But if the struct or the pointer itself would be some member variable that sticks around, a weakptr would be useful
Yea was just reading more into them. Going to keep it in mind when I review all this weeks work tomorrow.
Regarding mass mp game. Or just a game with few players but 300+ simulated actors. On which bandwidth you guys aim? 10kB/s per connection? More? Less?
i kinda don't get how they did StarCraft 1. Consider internet connection 20years ago and 400 moving units! Even in the very low update budget let's say 1 Netframe/s it must somehow transmit 400x10B(at least)x8 players. Which is 32kB/s out traffic from server. And i dont think they updated position once a frame only😱
RTS games are typically handled very differently to other genres.
They will typically send commands across the network and then execute them locally in a deterministic manner.
you send where the player told units to go, and they go the same place on each side
to put it simply
Yep
"lockstep determinism" is the term I think most use
So they aren’t constantly updating things like transforms across the network
there are RTS games that just snapshot replicate though
but you don't send updates literally every frame
and they are probably quantized a lot
If I was building an RTS. Unreal wouldnt be my first choice.
certainly not, but you could write a simple rts engine on top of it
just bonk the data over to regular unreal components/primitives to render or something faster if need be
Yeah, but we have what we have🙂 so we have to cope with ue somehow. I understand that I can update group only but it doesn't help. Just remember micro management of unit in SC or when one unit attack another from a group. So update group position won't save the day 🙁
Hi everyone. I currently develop a multiplayer co op game on unreal engine and I have this function for the inventory system. Everything works perfectly until I call this function from a chest actor in the map. When I call this function from chest's inventory component, on client won't work. Is there anyone who can help me about this?
even server function doesn't work as well on client idk why
What exactly is happening, is the function still running?
this function is called from onDrop function of a widget. It works but server function doesn't work on client (can't call the server function I guess)
I am making multiplayer snake for learning reasons. I am primarily looking at a couple of things:
- Overlap events (pickups). How can I make it so that this is validated, instead of the client saying "I picked this up, pinky promise".
- Maintaining a player's score. Where should I store this but also where do I set it? I want it replicated to everyone, but I only want the server to write to it.
- And lastly, probably a combination of the other two, where do I put the overlap logic and subsequent impact on the game (game mode? Since it's a win condition)
Server/player state(set on server)/Server
How do I restrict overlap to server?
I have a custom event set to run on server with an autority check on it, and I call it from the overlap event.
Is that ridiculously overcomplicated or the way to go?
Hi, is it a good idea, to use actor for replication of third party structure using custom net serialization? Are there any ways to send custom network packets?
Overlap already calls on everyone in theory
It's enough to lock it with ServerAuth or similar
No RPC needed
What does that mean? Sorry 😅
Oh, the authority check?
jop
- The Overlap question is answered already.
- The PlayerScore should be on the PlayerState, and only be set by the Server (which you can do from the Overlap event if that drives the Score).
- Depends on what the Overlap all does. You can do a lot in the Snake/Pawn/Character/whatever and then move any kind of Scoring Logic to the GameMode.
Are you calling a ServerRPC on/inside that Component?
Very vague question. You'll need an ActorChannel to replicate the property I guess.
That’s a thing I guess that confuses me. If the client sets something on player state, does it get synced back up? I’m not too worried people will cheat on my snake game lol, I just want to make it impossible by not trusting the client
Ooooh
I've fixed the problem by SetOwner function. Thanks anyway
Hm, I gotta ask though, how?
You need to set it specifically on the server? That explains so much
Cause for SetOwner you need to be on the Server @frigid fox
And if you are on the Server, why do you need the RPC? :D
And if that Chest is in the Map, then why does a Client own it?
If think what you are missing is some sort of "InventoryManager" Component that sits on the PlayerController and routes RPCs
So you can call Server_OnDrop(InventoryComponent) on that Client Owned Manager Component
And that ManagerComponent then does InventoryComponent->OnDrop
when the player interact with the chest I set that player the owner
yeah
Yes
I wasn't on the server that was the problem
Alright, then you might be safe. If not, then you will have to think about routing the RPCs. Just trying to make sure you aren't coding yourself into a corner.
I see yeah you're right
Yeah I get it now .I wasn't expecting interaction with the chest to be one player at a time
Cause only then it works with the SetOwner stuff
😅 yes make sense
Is there a way to package a multiplayer game with a dummy test server. (Like the preview in the editor itself)
Dedicated Server?
I am very far of to completing my project and I just need a packaged build which has UI visible
That doesn't answer my question :P
There is no "dummy server" fwiw
how can I make a very simple dedicated server, my goal is just to be able to send it to a friend and see the UI
(in single player, no actual multiplayer thing is done yet)
DedicatedServer, by definition, have no UI
I meant the game itself, my widget events are "Run on owning client" so my whole UI is not visible when I package the game
All the logic of the game works just no UI. I need to send it to a friend and I want him to be able to see that UI. What is the simplest solution to the problem?
I have a hard time answering this, cause what you write doesn't make enough sense to actually understand the problem
If you want to send the GameClient to your friend, you can package it and do so
There is no Dummy Server
If your game uses DedicatedServers, then you need to package and send/host that one too
You never even answered if it does
I am sorry, basically when I package my game none of the widgets (UI) are visible.
Then that's a bug in your game
What is to the left of this
So that's in the PlayerController
yes
If that's the intended code flow, then you are indeed expecting a DedicatedServer and player's themselves can't be a ListenServer but only connect to a Dedicated one as a Client
Is that correct?
I assume you are testing the game in Editor via "Play as Client"?
Yes
Correct. That is what I am trying to replicate in a packaged build.
If your friend has no access to UE and the project, then you need to also package a DedicatedServer
And either send that to him so he can connect to it locally, or host it and make sure he can connect to it
To package a DedicatedServer you need a Source Build
Host it locally means opening a command prompt right?
I don't want to open ports xd
Hosting Locally, in terms of DedicatedServer, means he starts the Server locally on his PC
Yes that would be the goal.
If he also doesn't open ports, the only he can connect to it though
That is not a problem, as I said I just want him to be able to see the UI and move around (singleplayer)
Right, yeah so if you don't support actual Singeplayer, then you gotta package a DedicatedServer and send that one too
Is there a simple way of doing that?
Depends on what you call simple.
DedicatedServers require a Source Build
So not the one you downloaded from the Epic Games Launcher
You will need to download the one from GitHub, then download all the requirements (follow its tutorial) and build it via VisualStudio for example
Sure, I think I can do that
But you require this anyway if your goal is to use Dedicated Servers
If the rest of your game works without being connected to a Server
Then there might be an easier option
Which is changing your UI code to show even for singleplayer
I am in early stages of development, so for now it is just singleplayer, but things are replicated and in the future a lot will be done in multiplayer.
And DedicatedServers are a must?
that is probably a better solution for now
I will clone my current project and chnage the logic so widgets show on singleplayer. Is that what I have to do?
I would just change it in general
No reason to clone a project
Just change the "HasAuthority" to "IsLocalPlayerController + Branch"
True -> Add UI
alright, sec
Yop
It worked, you are actually the GOAT
Thank you so much for your help and time, it really means a lot!
No worries
would that make sense or do I just have to chnage it back when I get dedicated servers working?
That makes no sense, no
You can just leave it the way you changed it
That works for either
does "Start Session" turn a standalone game into multiplayer? Or do i still need to do something like "open mapname?listen"?
Could you tell us what "Start Session" we are talking about?
Sorry I meant "Create Session" that exists in the player controller
CreateSession can be called in many places, but no, this does not turn the game into Multiplayer
Sessions and the Multiplayer aspect of your Game are two different concepts that work together.
Your Game can be a Multiplayer Game, without a Session.
You can also have a Session without being a Multiplayer Game (although this one doesn't make too much sense).
Most of the time you want both, which is Creating Session and then turning your Game into Multiplayer Game.
Multiplayer Game here means that your Player opens a level with ?listen, effectively becoming a ListenServer.
Oh ok, I was trying to figure out how to turn a standalone game into a listen server without reloading the map.
The Session part is just a system that helps your players to discover online games.
Not possible
Oh ok :/ Well thanks!
I'm taking an online udemy course and I'm trying to apply it to my situation. Players should be able to spawn a shield (actor) whenever they press a button. In the shield actor BP I've set replicates and replicate movement on. This didn't work... I learnt that replication needs to be run by the server.
The course specifically states that all spawning should happen in the gamemode blueprint and the GM is always run on the server.
So my idea is when a player spawns a shield, the pawn BP would call a function in the gamemode BP which would then call a shield spawn function in the pawn BP but since it's being called from gamemode it will be run from the server.
I just want to confirm my understanding because this all seems kind of backwards but this is roughly what was shown in the course I'm taking.
- Spawning can happen wherever you want, server or clients - it depends on your needs. But yes, if you want an Actor that exists on all clients and it's a consistent instance, then yes, you'd need to do it in the server domain.
- No, you don't need to spawn things in the GameMode. It was advised as such probably b/c the GameMode is guaranteed to only exist on the server, so it wouldn't lead to confusion, but should is a strong word.
To give you an alternate way to demonstrate spawn doesn't have to happen on GameMode: you can create an RPC to ask the server to spawn the shield for you virtually in an Actor that both the client and the server owns: PlayerController, for example, or PlayerState. I am not saying its ideal, I am saying its possible.
Thank you. I don't think I will then. I feel like going back and forth between the GameMode and my Player Pawn is more confusing. Let me see if I can get it working
I agree with you. You can spawn this shield of yours in the PlayerPawn itself - you don't have to bridge via the GameMode. As long as your PlayerPawn is owned by the client - it probably is, - you can use an RPC to request the server to Spawn it for you, all within the APlayerPawn class with no interference of GameMode.
ugh.. so dumb but I really need more clarification. I'm trying to implement a listen server so one of the players will act as the server right? You said "As long as playerpawn is owned by the client" I'm wondering if what you said means that the player acting as the server won't be able to use this spawn functionality that the other player clients will have
Yes, one of the players will be the server. I mean, these terms client and server are a bit convoluted when speaking about listen server. I meant to say host and remotes.
So, "as long as PlayerPawn is owned by a remote"
And when I say the word "owned", I mean, when you call the SpawnActor function (in Blueprints), there's one parameter called Owner, and that's what I am talking about.
I don't know the process you are going through when spawning the Pawns of your players, but chances are high they are already owned by your remotes/clients. So all you have to do is calling a Server RPC on the PlayerPawn class itself, and inside this RPC, you call the SpawnActor to spawn your shield.
Reading the unreal docs on RPCs it says it's for unreliable events and my spawn is integral to the game so it needs to be reliable.
You are building a game while learning Unreal while learning multiplayer - trust me, there's a lot for you to digest before you have to worry about the reliability of your RPCs. Don't worry about it right now. Just make it work so you can get the grasp of it.
I'm just wondering why you haven't recommended this? Will this not work? It runs on server and it's reliable.
I appreciate your help
I see this being the easiest and most intuitive way so as long as it actually does then I'm going to proceed with this. I want to learn good "coding" practices or at least understand when I'm taking a short cuts so I can fix them in the future if need be.
I was taught I should go through the GameMode which just like a lot of back and forth, maybe it makes sense if I want to check for cheating in the future but for now a simple run on server function is great assuming it works and isn't terrible practice for some reason.
GameMode will do nothing extra for you in terms of cheating. That is, the cheating problems you'd face by spawning your Actor in your GameMode vs. spawning it on the PlayerPawn would exist all the same. Also, RPCs, like everything else, is just a tool. "Good" vs. "bad" will depend on a lot of factors, and are really tied to the constraints of your game. I won't spiral into the matter, but brace yourself - you have a really long ride ahead of you. Good luck!
I'd really advise you to read the Network Compendium here: https://cedric-neukirchen.net/docs/category/multiplayer-network-compendium/
Also, WizardCell's excellent multiplayer tips & tricks: https://wizardcell.com/unreal/multiplayer-tips-and-tricks/
Thank you. I heard multiplayer is hard. I will read those now thanks.
How much can unreliable RPC's be delayed? And can they be totally scrapped, so they won't even arrive to the client?
forever, yes
Can I somehow check if they haven't been sent yet?
by digging into low level net code I guess? Why would you need that?
unreliable RPCs are fire-and-forget, you shouldn't think about them once they're sent.
For debug. My I'm sending about 80 of them, and about half of them ever arrive, and I would like to know what happened. I don't think they should be scrapped, as I'm sending from localhost to localhost
Hello, I'm trying to make a game with a dedicated server, but to be honest it looks very complicated. How hard would it be to make the game listen server based and then switch to a dedicated server later?
Its based upon same principles, like RPC's and replication. The difference is, on the listen server, you have a player hosting a game
The thing that really differs is the design. While making listen server, you basically have to make a dedicated server, with keeping in mind, that one player is still using it
Btw. Is there a function that returns true whenever is running dedicated or listen server?
UKismetSystemLibrary::IsServer()
I am trying to develop a very basic inventory system but I hit a wall with a sync issue that I don't really have any idea how to solve it
I started off the Lyra example so my logic is this:
- a
FInventoryEntrythat implementsFFastArraySerializerItem FInventoryListthat implementsFFastArraySerializerUInventoryManagerComponentthat implementsUActorComponent. this class has aUPROPERTY(Replicated) FInventoryList InventoryList- the inventory manager component is added to the player controller
when an item is added to the inventory (FInventoryList) I call MarkItemDirty and a broadcast message is sent to all the clients (using the UGameplayMessageSubsystem). I subscribe to this message on the UI so I can clear everything and re-render the items, and this is where I am having problems:
when I walk into an item drop as the server everything works normally, I receive the message and the item shows up in the UI. but when I am playing as the client sometimes I have up to 1 second of delay after I pickup the item and it showing up on the UI. and when I throw the item away the UI is always 1 "action" behind the items, I need to reopen it so the item is not there. for some reason when I call Entries.Num() it always give me the value in the past
Are you using the FastArray functions to make the broadcast?
Or are you sending RPCs?
Ive been developing a free plugin that does exactly what you are looking for.
Might be a reference point for you
I am using a broadcast subsystem, I think this is from Lyra let me find the code
void FInventoryList::BroadcastChangeMessage(FInventoryEntry& Entry, int32 OldCount, int32 NewCount)
{
FInventoryChangeMessage Message;
Message.InventoryOwner = OwnerComponent;
Message.Instance = Entry.Instance;
Message.NewCount = NewCount;
Message.Delta = NewCount - OldCount;
UGameplayMessageSubsystem& MessageSystem = UGameplayMessageSubsystem::Get(OwnerComponent->GetWorld());
MessageSystem.BroadcastMessage(TAG__Inventory_Message_StackChanged, Message);
}
this is called from the PostReplicatedRemove/Add/Change methods in the FInventoryList
Does that Subsystem call an RPC though?
Right
So it should be instantly called the moment the array updates
Which is what you are saying is being delayed?
yeah I am trying to figure out how it can be delayed since I am not adding the test latency from the editor
It should be near instant in that case
You might want to try and work out where the delay is occuring.
this is the subsystem: https://gist.github.com/rafaelalmeidatk/25f040987a998e024c08458d3325019b
Is it occuring during replication or after already being received?
That might help you understand if that subsystem is the culprit
I was trying to figure this out but I got stuck trying to understand if the logs were coming from the client or the server 
is there a way to split the output log for each player window?
Just breakpoint the FastArray functions
If they breakpoint immediately
You know its not that part of the system causing an issue
And likely something further downstream
Also
Make sure your Actor replication frequency isnt causing it to be delayed
but wouldn't the breakpoint trigger when the function runs on the server too?
Those functions are only called on Clients
ohh ok
uh I am having trouble with the breakpoints , they are not being hit but I think the issue is with my rider setup, I can see the logs in the output window
I added more logs and this is what I am observing:
- the
AddEntryfunction is called (to add an item to the inventory) - the
BroadcastChangeMessageis called right after to notify the UI, this function is called insideAddEntry, afterMakeItemDirty - I notice the delay...
PostReplicateAddis called and the UI is updated
I think this eliminates the subsystem from the issue because it looks like the array itself isn't updating fast enough
I will give a look at the replication frequency
Not sure where it would be coming from 🤷
I found the issue, I turned off net.UseAdaptiveNetUpdateFrequency and it started working with no delays
but I need it turned on for GAS 
thanks for the help! I will give a look at your project, I might need to rewrite everything again and it will be a good learning source
tbf I will probably just move the inventory to be entirely client side
So, I found out, that even reliable packages can be scrapped/destroyed. If I run a dedicated server in editor, as a separate server, the server can start sending packages before client is fully loaded
Any idea how to prevent this? Preferably, without sending additional packages from BeginPlay from the client
Basically, what I mean is AGameMode::PostLogin is firing before client is fully loaded and can e.g. receive packages
And?
Don't send data to them in PostLogin then
seems like an odd thing to do
and what do you mean by packages
TCP/UDP, basically RPC
Just updating player with the current state of the game. I though, that PostLogin is the moment for it. If its not, then what is a reliable, trustworthy place for it? When can I be 100% sure, that RPC won't be destroyed due to client being not prepared? On the client's PlayerController begin play?
Why are you using an RPC for that
property replication is the best place for stateful data that isn't one-off
Cause ISMComponent is not replicable
sure it is, if not directly then through a custom actor or component.
trying to manually RPC over a bunch of instance transforms is exactly what you shouldn't use an RPC for
trying to send a bunch of RPCs right as a player connects is a great way to get your RPCs dropped or delayed (if not disconnected entirely) due to the server trying to send everything over to the client.
I'm aware, and that's why I'm time splitting it. But let me explain
I remember, about year ago I asked about replicating objects just to particular clients. The thing is, this is a sandbox game, and I can't just replicate all the data to all clients
As each clients has its own render distance
Which is exactly why unreal has tools for that built in...
relevancy distance is a thing
not to mention repgraph for more advanced scenarios
But, this is for actors
Because there was no reason to not make it on the one actor. Currently it looks like: chunks are replicated UObjects, Placable blocks are instances
And there's your problem.
Chunks should be actors.
Actors are the primary unit of network communication, all replication goes through them one way or the other.
But then, shouldn't each chunk has its own set of components in order for relevancy to work properly? Or can relevancy work per instance?
I've already tested this scenario
It's not the only option.
And its unnaceptable for performance
Again, it's not the only option.
Nothing says the thing rendering your chunks has to be the replicated chunk actors themselves.
Actors could be used purely as a replication channel and on the client you could send events over to some central subsystem/actor/component/whatever.
By events, you mean rpcs?
No, I mean everything.
Property replication, RPCs, whatever.
Again, you do not want to be duplicating what property replication already does with RPCs - it's more work and you're going to do a worse job of it.
So, how to determine what instances from the ISM should be replicated using this method?
Actors have positions
and should have chunk data assigned to them
network cull distance figures out which to send to a client automatically
(or you can do custom relevancy if you really want)
when a client receives the actor (or an OnRep with the chunk data) you update that data in whatever does the actual rendering.
So then, after all, ISMC can be replicated automatically, and even partially replicated?
I didn't say that
I doubt the important properties on ISMs are marked for replication
But the data that defines your chunks, whatever that may be, could be thrown into a replicated array and then read back in an OnRep on clients and fed into an ISM.
right
that's all actually makes sense now
So, store all the data inside actor chunks
Then use OnRep, and rebuild chunks when necessary
But, actors are heavy
not really
When there are very large render distances, won't it become a problem?
and I don't know how big your chunks are, but you don't even need one actor per chunk
9x9x9 distance as a sphere is 256 chunks
What can be used instad of actors?
yeah but how much data is it, how often is it changing, how big is it, etc. You don't need 1 actor = 1 chunk, each actor could be a 2x2 grid of chunks. Or 4x4. Or whatever. Tune it depending on need.
And prioritization helps as well. As can repgraph.
You can have closer actors be prioritized higher, and therefore receive net updates more often.
see AActor::GetNetPriority
Btw. is there a way for manually seting relevancy?
yes, there's a function to override
AActor::IsNetRelevantFor
though distance-based relevancy works out of the box (if enabled in config and NetCullDistanceSquared is set on actors that need it)
and you can set things net dirty I guess?
Is it a question for me or siliex?
You mean fast arrays replication?
I don't think that's what he means but using fast arrays for this isn't a bad idea anyway.
Mostly for perf reasons.
Is it a bad idea in literally any scenario?
it isn't a bad idea
fast arrays are more complex but they're much more performant if you need to be dealing with lots of little changes to a replicated array.
I've heard opinions, that fast arrays are basically in every way superior to normal arrays
And want callbacks for when specific items change rather than only knowing when "something" changes and not specifically what item.
They are... pre-iris.
but they take more effort to set up.
I mean AActor::ForceNetUpdate for when you need stuff to be sent to avoid needing to wait for relevancy etc without changing relevancy
With iris, fast arrays are mostly unnecessary for their performance (still need them for per-item callbacks). But I'm not going to recommend using iris to anyone who isn't intimately familiar with the engine.
the good news is you can more or less drop in Iris once it's ready
iris sounds like fun then
It's great. It's just unstable, hard to debug, and requires a ton more boilerplate when you need custom serialization.
I am going to say that making some fast arrays will be less work than using an entirely new beta netcode backend that could do things you don't want that epic hasn't fixed
Is it just a current state of things, or will it persist?
heh
Current state of things except for my serialization comment
there's no indication that's getting better 😦
It's all in the service of not having it in the same file it seems
Eh, not so much that
More that NetSerialize methods in the current system are really simple. In iris... they're not.
But for most things you don't need them.
Almost everything else is a drop in replacement for the current replication system
bugs/instability aside
Iris serializers can be fairly simple but even the most simple one will have 3x more lines of code and macros
From what I know, switching to iris in the future should be mostly seamless
but the cool thing is... Iris kind of precludes the need for a lot of hand written serializers in some ways with delta serialization
it's the one thing that isn't
Iris will warn when you have old netserialize code defined for a struct with no iris serializer
but it will still work and just use the regular reflection serialization codepath
So, summing up - time for rebuilding building system
assuming said type works with regular uproperty serialization
Pretty much.
Trying to use RPCs for property replication is almost always a bad time ™️
unless you're riot and making valorant, but that was before push model was a thing
I'm riot but in different meaning, lol
Good think I designed code to be modular, so at least I don't have to rebuild e.g. item system
I mean tbf the "interface" to your chunks could still be the same single thing, but the place the data is being stored and the way the data is sent over to clients will change.
one thing I'm thinking of trying is to see how hard it would be to add my own extra piece on top of the replication bridge to help with my ECS crap as that's one big thing I'm missing... It's simple enough to RPC commands around but persistent state is just going to be insanely annoying without taking advantage of that
Really depends on how you want to go about things.
I think I should probably settle for pairing up the larger entities with uobjects/aactors that exist purely to ferry over their state... but that would almost certainly mean a custom iris replication fragment or serialization (not mass fragment...)
tbh sounds like you need to make a mass bridge like we have an actor bridge
good luck lol
there can only be one bridge, right?
the funny thing is Iris internals have no clue what a uobject is... there's actually not a lot in there that relies on actors at all
Ok, thanks for all the knowledge. I need to go on the walk rn to think a little about rebuilding the building
so yeah, I would probably have to extend the aactor bridge and add my stupid stuff on like a sidecar
idk that you have to extend it
just make a new thing that works similarly
you're not replacing the actor bridge, just making a new system that does something similar but for mass
This would be in service of having entities become network objects
which honestly... I don't know if they need to be in some ways besides taking advantage of actor replication style stuff
like distance based relevancy
Mass replications is just a hand written fastarray template per broad category of entity
which is a very... incomplete solution
you can't add new components over the network, that would be a new fastarray
which in some ways I would say makes sense, you uh, probably don't have that many different kinds of network primitives
but it still sucks when the data is so simple as is
one thing I tried: having a fast array per component type
which vastly simplifies the setup but was very bad for bandwidth... I could... chunk it I guess ironically
One more question. Can only actors be relevant, ro variables inside them as well? E.g. I have 2 arrays, and I want one of them to be relevant just for one player, and second one, for other
The only control you have over that is property replication conditions, which are not that granular.
the easy solution is to just write to objects owned by that actor if it's just for them
player controllers have replicated values that are just for that player for example
for just raw properties at least
so instead of storing the two arrays in one object, you just have them write to the object owned by respective the player
Storing chunk data inside controller would be a bad solution, because of the variations, data replication etc.
it doesn't need to be the only place this data is stored, it could serve as a temporary thing in X state
but yeah this seems zany for something as fundamental as chunk data
but I've never made anything quite like that myself, I have no real hot takes
The idea is:
- Make an actor that is the cluster of chunks
- Each chunk is a separate object or at least array
- Each cluster can hold e.g. 4x4x4 such chunks
- Cluster takes player position into account for relevancy, and then, based on that distance replicate only particular chunks
I wasn't here for the earlier part of the conversation but... how much is going on in the chunk?
I think your idea is sensible... it's similar to how Mass replication bubbles work afaik
Each chunk will be holding following data for now:
- Blocks(from my benchmarks, with current world gen system, some can hold even up to 1500 blocks)
- Block's custom data stored with
FInstancedStruct, for e.g. some machines
In the future:
- Entities, and their state
I would argue FInstancedStructs are some wasted data...
each one has what type of thing it is as the scriptstruct
So, use UScriptStruct instead of FInstancedStruct?
Unless you need polymorphic structs, just use the actual struct type instead of FInstancedStruct
I need polymorphism. Each chunk can store some item's data, and it is unknown at compile time in what chunk what data is to be stored and replicated
👍
But then, should I use UScriptStruct? I've never used previously, and idk if it is a good option for this
FInstancedStruct is fine. Its net serializable.
no, it IS using that
I'm just saying you may be sending repeated data in the form of "this is the type of the data" as it has to
so if you have 500 instances of FMyStruct2
a large amount of that data will be just... 500 instances of the ID of the scriptstruct over the wire
but if it's random and sparse by nature it might be easier to just do that
the alternative I think being something where you have a buffer of N FMyStruct2 sent over in one bunch
also... oodle compression exists so don't go crazy here until you see a real bandwidth issue imo
I havent really benchmarked FInstancedStruct bandwidth.
I need to though
Its a core component of the plugin im working on.
In my use case though it wouldnt really be an issue.
It's still an absolute blessing to be able to send it over at all (bless ye Jambax)
but it just has to have some idea of what the data is for by nature
Yeah my plugin wouldnt be possible without it
All hail the great Jambax
I would like to use chunk clusters, but I think I would need some additional info about what to do with irrelevant data. If there would be 2 players, and they would load same edge clusters, then it would replicate for each of they whole cluster, this including chunks they shouldn't render
Is dereferencing a pointer on pre replicate an option, in order to prevent object from build replicated?
Probably this question was asked a trillion times:
Where can I store a variable that can be easily written by server and all the connected users.
My case is this:
All players are in game, and I want each of them to press a button on their controller to signal that they are ready for the game to begin.
I have a integer variable with the number of the connected players, and I would like to put a global variable that the server and any client should update with +1 when they are ready. When the number of "Ready Players" is equal to the number of connected clients, the game should start. How can I do this? Can you point me way to achieve this?
Id just stuff it in the lobby GM
Playercontroller RPC their new state Ready/NotReady
Assosiate it withbtheir controller and you know exactly whos stalling
Can even notify them
Any drawbacks of doing client loaded inventory struct, where only the key fields are replicated?
Guess im forced to include the DT in client builds but no biggie
Please explain like I'm a retarded 3 years old noob 🙂
Actually it's probably more sensible to use GameState, since it's just there for all players already 🙂
SetReadyState includes a bool
SetPlayerReadyStates includes the assosiated PlayerController reference, and the bool they've already sent
Hmm, so apparently GetOwner<APawn>()->IsLocallyControlled() returns false on UActorComponent::BeginPlay() for a component on character, since it's not yet possessed right after spawning is finished, on the listen server. Is the way to do this creating a delegate to be called when pawn is possessed so I can check again once it's possessed?
you can just bind to its OnPossessed
Oh there is one already?
Isn't OnPossessed just a function?
OnPossessed is for player controller
but even so, just adding your own delegate to that is ofcourse ann option
Yeah that's what I'm planning, my question is if that's the way to do it
Got it, thanks
Is there a tutorial I can follow, I'm bright new to replications and all this.
Guess i won't be making any more tutorials 🤔 😅
Oh, no, I mean an existing one 🙂
hehe
check out Exi's multiplayer compendium
first pin in this channel
read it 3 times. then 3 more times
if RPC run on owning client is called on the client, will there be a load on the Internet or will the ue skip the Internet part?
if a client calls a client rpc, it will run locally
hi! is there any way to set initial value of my camera to black (alpha 1)
in blueprints
because i have an issue when connecting to remote server, there is a period where the camera is transparent (alpha 0)
it seems like this default camera is initialized before everything else
just to clarify i'm using bluepring project, and the camera is default
Hi, can i use NetDeltaSerialize to replicate struct, that is not USTRUCT and can’t be UPROPERTY?
negative
It has to be a native UPROPERTY member of an object. Can't be embedded in another struct either.
Are there any ways to make struct into UPROPERTY? Or maybe there are ways to replicate non-UPROPERYs?
Not unless it's a USTRUCT no
The engine can only replicate UPROPERTY data
Since the whole replication system is built around reflection
Maybe there are ways to send data to clients as packets? Or some other low-level way to manually send data
Are RPCs fast enough to make like 30-60 updates per second?
You can't rely on it in any case
RPCs will send as fast as you call them, but calling reliables at that rate is not advised, and unreliables are likely to be dropped since you'll likely saturate the connecton
Maybe best to explain what you're trying to do
You could always open your own socket and do your thing ?
I have a world structure from the external ECS(Entity Component System), and i need to add multiplayer support to it
Generally there are few arrays, i only care about 2: entities and components
Yet as it’s not USTRUCT, i need to make my own replication method for it
Are there Unreal modules for it?
Old but seem to cover some of it (altho exposed for bp)
Havnt tried any of this myself, just fyi
Yes
Seem to cover the tcp socket, but also python script
Should be enough here to get you going, or atleast see if its feasable for you
If you're gonna send tons of the same data all the time to all clients, might be worth investigating multicast tech aswell...
Thanks!
As i understand it, multicast UDP should not be problem even with occasional packet losses, if I communicate around at around 60hz
Thats what im thinking.. and far less trouble for your server as the network equipment does the copying of the packets
Not sure if its possible to check if all equipment supports it but i believe like 99% of it does already, if not all ...
Nvm, im wrong.
About the supprt of it *
Ipv6 demands multicast support 😄
I also have concerns about how safe actually packet loss is. Im talking about potentialy(theoretically, but if players want, they can spawn as much enemies as they feel like) thousands of units, so i should not send full data, only diff of it. If i do it, packet losses may be fatal, as client's version may get very outdated.
At what point do you realise you're just reinventing all the stuff the engine does for you 😄
I don't know about any other ways to do it, sadly :<
You'd send "full frame" packets from time to time
To ensure equal states
But this gets complex. Fast
Like, ECS i plan to use can't be turned into UPROPERTY, and i have no idea what other engine tools i may use to replicate such structure
I also think that settling to Mass may be not so bad of the idea after all, creating such deep integration seems like a very long and tedious work
when i connect to a server, in a blueprint project, where is the first hook where i can add some code
when i say first i mean it, first of the firsts
i need something before camera gets initialized
Mass does indeed have at least some primitive replication support
actually you can.
anyone maybe able to help me figure our why my projectiles dont always count when hitting the host client at distances but it works close by and works perfectly if the host shoots the other client close and far?
if you're using GAS.. you can create a new globals and force the engine to use your defined globals.. pretty much you want to create a new effect context handle completely .. I did this by overriding UScriptStruct to return the actual struct used for serialization, than override NetSerialize to make it uint32 to open up more streamed packets instead of uint8.. than you just need to make RepBits for each type of struct you want to pass along... when you send data via NetSerialize you are really just sending a binary packet of 0's and 1's across the network.. all you have to do is change the key so that the extra 0's and 1's mean something.
NetDeltaSerialize requires a history state which needs to be mapped to a UPROPERTY
NetSerialize will work, but NetDeltaSerialize needs a lot more plumbing
But yeah it's more than feasible here to just wrap the data type with USTRUCT and forward the calls appropriatelly
anything can be a USTRUCT ultimately
bool FCustomGameplayEffectContext::NetSerialize(FArchive& Ar, UPackageMap* Map, bool& bOutSuccess)
{
uint32 RepBits = 0;
if (Ar.IsSaving())
{
if (bReplicateInstigator && Instigator.IsValid())
{
RepBits |= 1 << 0;
}
if (bReplicateEffectCauser && EffectCauser.IsValid() )
{
RepBits |= 1 << 1;
}
if (AbilityCDO.IsValid())
{
RepBits |= 1 << 2;
}
if (bReplicateSourceObject && SourceObject.IsValid())
{
RepBits |= 1 << 3;
}
if (Actors.Num() > 0)
{
RepBits |= 1 << 4;
}
if (HitResult.IsValid())
{
RepBits |= 1 << 5;
}
if (bHasWorldOrigin)
{
RepBits |= 1 << 6;
}
if (bIsBlockedHit)
{
RepBits |= 1 << 7;
}
if (bIsCriticalHit)
{
RepBits |= 1 << 8;
}
if (bIsParried)
{
RepBits |= 1 << 9;
}
}
``` etc.
in that i passed along bIsBlocked, critical, and parried in the newly created effecthandle
as an example
do the same with Ar.SerializeBits
i mean.. yea it needs to be UPROPERTY because it needs to be able to to communicate with the reflection system
but you can really put anything in it.
hi all, do Pawns or Characters that are simulated proxies have any info about controller rotation replicated in them by default?
my use case is AIController possessed pawns, the server can get their controller rotation but clients can't, unless I manually replicate that through pawn? but it seems like something that should already be available
that makes sense since all AI functions are passed on server only
I did find something, pitch is replcated with RemoteViewPitch
anyone?
sounds like you dont have network prediction setup and are running just pure OnComponentHit ?
pretty much whats happening is you have some desync betwen host and client locations.. your clients think it hit the host, the host is saying it wasnt hit
are you using any sort of network prediction key with your projectiles?
or using any sort of local prediction whatsoever? or is the server pure auth?
could also be distance based net culling
maybe try ticking "always relevant" on projectiles and see if it helps
okay ill try that ty so much
yes its just component hit how do i use the pridiction
Can anyone explain why both the client and server UI end up on the server instead of having one UI on the server and one on the client?
Good morning! Good afternoon! Good evening!
I'm noticing jittery simulated proxy movement using the stock CMC and AddMovementInput, can anyone think of something I should look into?
The "Event Possessed" can only be run by the server
if you hover over the little tower icon on the top right of the event node it'll explain a little more
I finally fixxed it, thanks!
Hey everyone! For multiplayer, what type of code should go in game mode / game state? I had a conversation with someone yesterday in this discord who said to completely ignore them and just do it inside a replicated actor but that sounded like bad practice to me, otherwise why would they exist
Currently I am handling any checks for if score should update, if a team wins the game, etc in game mode and if it should it fires a delegate to game state that can replicate to clients if needed
Here’s the context if anyone is interested: #blueprint message
GameMode generally defines the rules, GameState keeps general variables and/or anything the client needs access to.
Whoever told you not to use them is out of their mind, but you can also use components for example and append them to both.
That’s what I thought. Thanks for the info
So if game mode is setting rules, what is best practice for when a rule is met? Broadcast a delegate to game state to run something?
There's really no hard and fast rules honestly
If you are talking about our conversation I didn't say that at all
Not you. I linked to the convo here
yeah you can ignore those actors but I don't really get what they're saying at all
Yeah I wasn’t too sure what to make of it either so I just wanted to confirm lol
I’m going to be on my computer in like 10 minutes and I’ll send my flow here. If you are still on I’d appreciate if you could tell me if it’s bad practice 😁
So currently, here is an example of what I do:
- game mode starts the round & begins a timer on game state
- when game state timer ends, calls a delegate that game mode is bound to
- game mode determines which team won and increases that value on game state
- repeat
Also some other scenarios like:
- game mode checks if all players on a team die before the timer ends
- updates score value on game state
- stops game state timer & restarts round
I'm having a hard time understanding this section from IsLocalController(), in what scenario would this statement be true for a PlayerController?
if (GetRemoteRole() != ROLE_AutonomousProxy && GetLocalRole() == ROLE_Authority)
{
// Local authority in control.
return true;
}
Listen server host
If the remote role is autonomous & local role is authority, means the player controller is another player's
but if the remote role isn't autonomous, it means we're the server & it's our player controller
oh makes total sense, cause even if they replicate the "same" thing they are still different objects
I could be wrong here, My first run through of my main game loop I was trying to figure out how I handle game mode versus game state and put too much in the state. Where as now the state just has some replicated stuff.
In your case I feel like with the round timer I would handle that timer on the server but then send it to the game states. I assume It is just a round timer so I don't see why the client should have their own things versus passing info.
I always doubt myself tho so I could be wrong haha.
Edit: ALSO, check out the Lyra sample project. It's on Epic GitHub too if you don't want to make. I read through a lot of it when fixing up my stuff.
Thank you for the advice. I will look into this 🙂
Why TMap and TSet are unable to replicate?
I mean, from the technical point of view. What is preventing epic from adding support for replication?
How can I multicast a GameMode Event onto all Clients? I'm updating a Material Parameter to change a Selected Person to the Color Red, but it only works on the Server.
1- The GameMode only exists on the server
2- Don't use RPCs for this, use a replicated variable, possibly on the player's pawn or player state if it only affects one player.
Cool, made the Variable Rep Notify on the Pawn, and I set it in the gamemode and that seemed to work.
Unlike TArray, the relative order of TMap elements in memory is not reliable or stable, and iterating over the elements is likely to return them in a different order from the order in which they were added. Elements are also unlikely to be laid out contiguously in memory.. due to this they are not exposed to the replication system
There's a lot of things that happen under the hood when something is marked to replicate.. for Instance an item that's replicated is given a unique name, etc. And identified as a unique item In the replication system. None of that is possible with TMaps or TSets
Hello, guys!
I'm trying to replicate my animations, but the **server **animations only work on it and the **client **animations only work on it, neither replicates to the other. (I'm using multicast, my error must be somewhere else and I must be making mistakes in a noob way)
I have an animation state machine, ABP_Mage, and I'm setting it in a variable (in the character). After that, within an event (server only) I call the animation event (multicast)
and it always gives the error, for example:
"Blueprint Runtime Error: "Accessed None trying to read property ABP Mage". Node: Set SpellBall Graph: EventGraph Function: Execute Ubergraph BP Third Mage Blueprint: BP_ThirdMage (my player character)"
Hello, multiplayer noob here, how would I go about making a bunch of different multiplayer game instances, like how a Valorant server hosts many games at once?
I don't think there's any evidence that valorant hosts multiple games at once in a single process.
They run multiple processes per physical server, that's all.
Unreal has little to no support for hosting multiple separate multiplayer worlds in a single process - it would require some pretty hefty engine changes if it's even remotely reasonable to do at all.
and just to illustrate... https://playvalorant.com/en-us/news/dev/how-we-got-to-the-best-performing-valorant-servers-since-launch/
Note that they are talking about multiple processes. Not multiple games per process, just multiple processes.
Does anyone have any good advice for making a Delayed Respawn System for Multiplayer in the GameMode Blueprint?
The Main issue I have is when multiple die at the same time, it can't handle respawning all of them. I was thinking of building an Array for "Awaiting Respawn" but not sure how to delay it properly.
you can store each awaiting player in a struct that also stores their individual respawn timer
How would I use that Respawn Timer to respawn them? Would this be something done on Tick or would I need to move this logic to the Controllers for each player?
how does your current system work?
On Damage Receive on Pawn, goes to Health Component, then if Health is <= 0 it will call a Respawn Function on the Player Controller, which disables HUD stuff needed, then does an Interface Call to the Gamemode for "On Player Killed" where I pass all my references.
I have all my respawn Logic on the Game mode for finding spawn and possessing.
and the "on player killed" call just uses a delay and then does some stuff im assuming?
Yep, some Gamemode specifc stuff, but because of the Delay, it can't handle multiple people dying at once
The Controller References would then change as well, so it will skip the first player killed in the delay period
use a timer
not a delay node
and store the ones that need respawning
C++ is a bit more simple to do that BP, bp is very limited with this kind of thing
Cancel the timer when nobody is pending respawn I assume. and I can timestamp the death and respawn when time is greater than added respawn time maybe.
one thing you can do, why doesn't your HealthComponent or PlayerController have it?
ideally your player controller will schedule the respawn
and fire into the gamemode
this way its linked to the player not the gamemode and you can use delay
I was thinking that, but Respawn time is going to be specifc to the type of gamemode
Some gamemodes may handle respawn differently
Hm, that is true
I'll give it a shot and see what I get
Thanks for the idea. Seems like that'll be the easiest route
Actually Genius, worked perfectly. I made a Core Game Mode with a Respawn Timer Varriable, and all child Game modes can change it now. This runs on the Controller.
Thanks for the help.
When I play as a client my gun is stuck in air but not alway. It happens only sometimes
Does anyone know how to fix it ??
Variables not marked as UPROPERTY() inside Fast array replication struct won't be affected, nor serialised, right?
Only the Array of the FastArraySerializerItems you designate in the NetSerialize function will be net serialized
UPROPERTY()
TArray<FFastItemInstance> ItemInstances;
bool NetDeltaSerialize(FNetDeltaSerializeInfo& DeltaParams)
{
return FFastArraySerializer::FastArrayDeltaSerialize<FFastItemInstance, FFastItemInstancesContainer>(ItemInstances, DeltaParams, *this);
}
See how the ItemInstances property is passed in as an argument to the delta serializer
I expressed myself unclearly, mb. I meant, if I would put some data inside FFastItemInstance(in this example), that is not marked as UPROPERTY, it won't break anything?
No, the FFastItemInstance is a regular struct that just inherits from the FFastArraySerializerItem which just enables it to be used with the FastArray.
It follows normal replication rules for USTRUCTs
So anything marked as UPROPERTY will be serialized by default
(Unless you override the NetSerializer function)
ok, ty
Why Fast Array Replication events, like PostReplicatedChange(const struct FFastArraySerializer& InArraySerializer) or PostReplicatedAdd(const struct FFastArraySerializer& InArraySerializer) give const references to the serializer struct? Is there something unsafe about modifing data from up there? E.g. if I hold some pointer inside serializer struct, and I want to modify some data via this pointer, should I const_cast?
No you dont want to do that.
The FastArraySerializer has similar functions
Which return the index of the element in question
You can apply modifications that way.
Also, you wouldnt want to make modifications in those functions anyway as they are only called on the Client
So you would only be modifying the Clients version of that element.
Checkout how I use it in my plugin here: https://github.com/mattyman174/GenericItemization/blob/master/Plugins/GenericItemization/Source/GenericItemization/Public/GenericItemizationInstanceTypes.h#L249
I'm aware of this. It is for modifing some external data, e.g. items in the equipment interface
is replicating an int array with 10,000 elements a bad thing?
For such large arrays use Fast Array Replication. Especially, if you are changing array in small portions
If I may ask, what is the purpose of such large arrays?
The cost to hit 3 games per core was almost certainly Vangaurd, not worth all the margins on the market
@meager spade do you know anything about my problem.. ? I shared a video
This is the code...
When I set a pickup weapon trace on owning a client replicate it works fine but not showing on the server. I don't know how to implement that
hey guys, where do you suggest implementing player game data in multiplayer games? GameInstance or GameMode?
what kind
player score , name and ...
Hi all,
I have a replication issue in Unreal egnine 5 and I don’t know what is wrong.
I call an interface event in my replicated CharacterBP in an non replicated event:
(Image 1)
It get executed on my pickup Item:
(Image 2)
It prints “server” on the server and “client” on the client which is fine:
(Image 3)
This event is Run on Server but only the listener server prints “2” and the client does nothing:
(Image 4)
So the actor doesnt get destroyed (on server and clients which is very strange) and the client cant execute this function. I have no idea why this is happening. I hope I can get help here.
Thanks!
Starting a fresh VR Template as Listenserver is ok, but if started as client returns this error:
Blueprint Runtime Error: "Accessed None trying to read property CallFunc_GetPlayerController_ReturnValue_1". Node: Enable Input Graph: InitializeInput Function: Initialize Input Blueprint: VRSpectator
Can anyone help me understand why APlayerCameraManager has multiplayer stuff in it? This is so weird to me
Hello, guys!
I'm trying to replicate my animations, but the server animations only work on it and the client animations only work on it, neither replicates to the other. (I'm using multicast, my error must be somewhere else and I must be making mistakes in a noob way)
I have an animation state machine, ABP_Mage, and I'm setting it in a variable (in the character). After that, within an event (server only) I call the animation event (multicast)
and it always gives the error, for example:
"Blueprint Runtime Error: "Accessed None trying to read property ABP Mage". Node: Set SpellBall Graph: EventGraph Function: Execute Ubergraph BP Third Mage Blueprint: BP_ThirdMage (my player character)"
If I have a struct called 'commands' that any 2 players can send a message to the server to add values to at any point, which replication type is recommended?
If it's to send to the server your only option is a Server RPC
no i mean some data we are going to store out of match, in a LAN game, and gonna load them every time that player logs in
I'd probably make a game instance subsystem
thanks
with this do you need to persist data even between server restarts? GI subsystem is still the best way but you'll want to look at save games or other serialisation and storage options too
hey guys, I'm following a paid multiplayer game course, and at event "Multicast Fire" it makes me set the player pawn not equal to owner at player index 0.
But doesn't that mean it will only work for those with player index 0?
If yes, how can I make that it changes the index based on the player?
If this was a paid course telling you to do that then seesh. I think this is a half-assed attempt at making so the effects don't play on the client that fired since that client presumably already played the effects locally
yeah but isn't that only going to work for player index 0?
yeah, it's a botched check. does this course ever explain the intent of the check?
it did but I genuinely forgot, because there's a lot of stuff going on so I tend to forget smaller details sometimes
so is it possible to change the player index value based on what player is playing?
well it depends on the intent right
because I have also implemented myself a simple recoil system that also uses get player pawn
hm, true
and that has to work for all players
well recoil is typically something that's clientside anyway
I was wondering how you would reliably engineer ownership problems without too hard reliance on the Player Controller.
On https://wizardcell.com/unreal/multiplayer-tips-and-tricks/#8111-example-usage this page they give some pointers, but I'm somewhat lost how to apply it for a bunch of actors.
I'm not sure why this is running through the multicast or why you use GetPlayerPawn(0) when you already know the owner of the weapon
nah the recoil system runs on a clientside event
GetPlayerPawn(0) when you already know the owner of the weapon
omg you're right
yeah sorry I am pretty new to game development
ah nevermind
though still, why does it need to be an RPC when the client would usually predict their firing first. you would add a delay to recoil otherwise which would feel strange
with the delay being proportional to ping
wait what do you mean?
the recoil works fine
yeah when your ping is 0
ah
but I'm not a big "networking in BP" guy anyway
yeah fair enough
after I complete this not full fledged game my intent is to learn C++
i tried to turn the FPS template into multiplayer
the thing is, when the client overlaps with the BP_Pickup_Rifle, the client is instantly kicked to its solo world.
what is the source of this problem ?
I just tried using network emulation and set the profile to bad internet connection and the recoil does work correctly
This is going to play animation for everybody, except the owned player
then it probably doesn't need to be an RPC then if it's being called from the client
fair enough
also even at low ping the fire event takes about 0.8 seconds before firing
this one
welp must be BP being slow
that seems pretty long in that case but in general, this is why games usually predict things like effects before the server has even processed anything
ah I see
I'll see if I can try optimizing it
question, if I call a client rpc from an actor instance and then immediately after tell it to destroy itself, will the call be executed on the client before it gets destroyed or is it possible to end up with some undefined behaviour, where it decides to destroy the actor and then it attempts to do the call?
If the RPC is reliable it'll be processed before the destroy call
If it's unreliable, no garauntees
I see, thank you
If you're running a Server and a Client and only replicating the game state and 'messages' between server and client directing input, the game should be deterministic purely off those messages right
Hey guys, my client can server travel when i test two stand alone games on the same pc, but not when i'm playing with two pcs.. does anyone know what i should look for?
The client sends an 'instruction', the server saves it, and every tick sends a message to progress the game with the array of instructions given
whatever the replication type of the event, i get this error. And the client is kicked of the session
Why is this not replicated? Does the node "is input key down" not support on client or the "get player controller from object"? Can't seem to figure this out, tips are much appreciated.
I'm very sorry for very long response 😟 . May I ask, please, how exactly can i wrap it with USTRUCT? Like, modify original structure, or create another USTRUCT and just reimplement all needed methods?
I'm not sure if this is a #cpp or #multiplayer question, I have a replicated component which I add to character on server. Then in the begin play I create a sphere component, add it to the component owner (character) and listen the overlap begin/end events. If I walk with another character inside that collision, it triggers overlap events on both server and all clients. But when I try enable/disable collision only server receives ovelap begin/end events. Clients receive nothing. Same thing is applicable for adding the sphere component as well, if there already is something that will overlap the collision, upon calling UpdateOverlaps() server receives the overlap begin event, but client doesn't. Is there something that I'm not aware about this?
Why not create the component in the constructor? Not sure that will help, just curious.
You're enabling collision on the replicated component and that replication isn't making it to clients?
struggling with an embarrassingly simple thing, got some enemies that randomise their outfits on begin play, just set mesh to random within array, and SOMEHOW I cant manage to replicate this. at all. wherever I make the event it just refuses to do anything. I can try print string and it shows me the random list of outfits, and yet setting it does nothing
literally just
dont know if multicast is even needed for enemies I know some things work with just server but things like their animations needed to be multicast
this looks like you're calling a server RPC to do it? Why not do it all on the server from the start? Clients can only RPC to servers on actors they own, which would presumably not be enemies.
oh yeah true, then I have no idea how setting up multicasts fixed some other enemy events
but the problem with this is that it naturally randomises differently for each player
Is it normal for the level blueprint to not run on clients?
well this is ridiculous
Should run on all
so why does this incredibly simple little script not work when everything else Ive set up in the enemy has worked as it should in multiplayer
it wont set mesh at all it wont do anything
yet it still prints string
I think it just refuses because something to do with calling from a child actor, I dont know, I only need it on this actor
What are you reffering to?
I'm sure you won't need to replicate the setting of the mesh, are you sure that the mesh component is set to replicate?
yes, it just randomises it differently on each client
Try instead of a server RPC, have an authority check and if it is the authority then set the skeletal mesh
does nothing, since its an enemy so it wont have authority
if the enemy exists on the server then the server has authority over it so you can do an authority check to run things only on the server. If it only exists only the client then a server check is useless
oh
then it should be working fine
but it wont
wow, god forbid I try to get one little thing done today
Skeletal Mesh Components do not replicate
You want to have the skeletal mesh be a replicated property on the actor
And set it in the rep notify
@oak pond
still randomises differently between clients
Only run the setting on the server
Not clients
On the server, grab a random mesh, set your replicated property to that mesh
In the rep notify, apply the replicated mesh to the skeletal mesh component
In Blueprints rep notifies run on both server & client so if you have a listen server, it'll still work
OMG thank you, yeah that was it, forgot it had to be a server event too
As to what Erlite is saying... i have a mesh color changer i was toying with a while back on my old player character using a repnotify... the player requests a new color, then let the server change the value, and the repnotify applies it on both the server and the client.
Hi guys
can someone explain me this,
I have a replicated actor that cant fire a server event "has authority " is showing that it is a client, and still cant fire any kind of server event. What is the option to make this replicated actor able to start a server event ? 🤔 thanks
You need ownership of an actor to execute Server RPCs
On the server side, use Set Owner on the actor
That is only if the actor is owned by one player
If not, you'll need to route the RPC somewhere else like the player controller
Since this seems to be doors, yeah probably not a good idea to set the owner to a specific player
Would it be frowned upon to always swap owner of said door ?
So you "own it" during the animation etc, but not after ?
So a server event when player interact with this actor should set owner ship to the player interacting with the object ?
what do you mean by ownership tho ? own do you set "this player is the owner of this actor" ?
Ehhhh kind of
Not the best idea to own stuff like doors in the world
and that would not be possible cause those "doors" are just a static mesh, so I can set any static mesh to move with this code to creat hidden doors haha
Setting ownership is an option, but unlikely ideal for a door
Better to route the RPC somewhere else like an interaction component or something, that sits on the player controller/player pawn
and this pannel can control up to 5 static meshes to open when entering the code
You shouldn't touch ownership in your case, it's just in general
Doors was probably the worst example ...
Generally if you're gonna do something like play an animation, the client will have told the server somehow already
Meaning you already fired a Server RPC from something you own
I was considering doing it for my NPC's, but i've gone the other path instead
At that point, why bother with setting ownership on the server ^^
I needed some event in return to the client 😅
On a server owned actor
It became weird, to put it mildly
Use a proxy that's owned by a player
Actually..... thinking about it, im just stupid about thisn
Probs better
if server fires this event, all doors moves in a replicated way since I set those static meshes to replicate movements
Yep
Thats a far better way
You want to do that on the server yes
Dialogue in this case. And they're already uobjects so easy enough
how do I get a reference to the player that is the host of the game ?
and from there your telling me I should Multycast the door movement rather than run the door movement on the server that automaticly replicates ?
in all cases if I want to multycast I need this actor to be able to run a server event.
Cause when there will be 10-20 players opening doors im not sure how it's gonna act if only have one function " This panel is currently opening this doors" into player controller and those are fired at the same time
I think I'd rather have those actors saying to the server "Hey i'm currently opening those doors"
So that the server can handle those doors at the same time
On the server it's always the first player controller
You do not need to multicast - make it automatically replicate
yeah I'm testing that right now, chat GPT said playercontroller 0 should always be the server / host i'm testing that to see if it's true xD
i guess it makes sense tho that the first controller is the host, but what if we change host at runtime ?
does it become player controller 0 ?
Is this 100% reliable in all scenarios?
Makes sense
then what if hosts leaves ?
I guess you should make a code that sets the best player connection to now be the new controller 0 ? But is that possible to set it's controller to be the new player controller 0 ?
Everybody gets kicked back to the main menu/default level
The engine does not support host migration, at all
Attempting to implement your own requires:
- A very very naive implementation that could work but is hacky and requires tons of tinkering. Players will still be kicked, but you can "reconnect" and have them rebuild the state. Players will need to know everything about the game to recreate the state.
- An actual implementation of host migration that requires an insane amount of engine modifications and additions.
my final honest conclusion about making a code that migrates hosts : Fuck it
So i made this to test if the player controller is always 0 but every clients and the host returns 0 to the print string x)
Did miss concept what a "Net player index" is ?
Player controllers only exist on the server & owning clients
So any player that isn't the host only knows about its own player controller
which means they'll always be 0 for themselves
Hi, guys!
I'm trying to replicate my animations, but the server animations only work on it and the client animations only work on it, neither replicates to the other. (I'm using multicast, my error must be somewhere else and I must be making mistakes in a noob way)
I have an animation state machine, ABP_Mage, and I'm setting it in a variable (in the character). After that, within an event (server only) I call the animation event (multicast)
and it always gives the error, for example:
"Blueprint Runtime Error: "Accessed None trying to read property ABP Mage". Node: Set SpellBall Graph: EventGraph Function: Execute Ubergraph BP Third Mage Blueprint: BP_ThirdMage (my player character)"
so the suprem technique of " get player controller 0" to find the host will never work if it is fired from a client.
So im stuck again with "how to get a reference to the host of the session from a client event into an actor that cant fire server event" ?
This code is pretty much not making any sence to me 🤷🏽♀️
but a multy cast is asking all the machines to do something on there side, it's not actually everyone watching one same moovie
It's everyone having it's own screen to watch a moovie if that makes sense
Animation blueprints do not replicate @primal trellis
Don't try to replicate them ^^
what we usually do is multy cast an animation or anim montage
What would be the correct path to follow?
well looks like his context is just playing a "cast a spell ball" animation
I thought it would make sense to replicate the animation blueprint
hmmmm ok
Whatcha trying to do exactly
do you just try to display an animation, or do you spawn an actor and stuff and projectile etc... ?
I want my character to release a magic animation and this is replicated for everyone
here the current status:
so yeah if it's just animation and SFX / VFX
I would do :
Input key -> tell the server he is casting a fire ball so we start a multy cast ( let the server spawn and handle the actual projectile / explosion)
Muty cast : play anim montage
I might be wrong tho, there is not only one way to do that and it depends on the scale of the project
Perfect, I'll try that way. Thank you for your help!
how to you display a specific animation / VFX / SFX to all clients then ?
@primal trellis does casting a spell have a start and end?
has an animation for casting and one for "releasing the skill". But they are two different
for VFX and SFX you could spawn a replicated actor that displays those on spawn, but I dont see any other way to make a player display an anymation on all machines ^^
Start with reading up on montages
Would suggest using a replicated property, which is the spell the player is currently casting
That way you can play animations when you set it (start casting) and remove it (stop casting)
Better than RPCs for this - a scenario would be a player popping into existence and you seeing them throw a spell without seeing them cast it
I do as the generated object, get its instigator. After that I make a cast for the PlayerState, and put which team it belongs to, to only cause damage to the opposing team
but to spawn the skill, I create a custom event and set it as Run on Server and call it by pressing the X button
Not the worst, but also easily fixed by using replicated properties instead of RPCs
Perfect, I'll do it that way! Thx!
Playerstate 🤮
Why not pawn?
I'd do it like
Time to do the hit -> if ThingImGonnaHit.Team != MyTeam -> do the hit
because I'm a noob kkkkkk
I don't know for sure, I needed a way to check the teams, but I wasn't able to do so using the tag on pawn. And I found this way
I did pretty much the same type of code from player controller ^^
That can work but then if you ever want to involve teams with other things like AI then you either gotta give your AI playerstates or otherwise work around it.
It's something I really plan, I'll try to find a way to do it for pawn. Thanks for the tip!
Even better, bake team-ness into your collision, if you have a set number of teams
Then the hits just don't happen to begin with
I think I understand, I'll try to apply that 🤘 🔥
Anyone got an idea what could be the problem?
This event is Run on Server but only the listener server prints “2” and the client does nothing:
Since it's a server RPC, the client won't execute it all
I was about to ask a question but figured out the answer while typing it out phew
Oh I explained it not 100% correct. The problem is that if the client executes it no one prints the 2, even not the server but he should do it. And the pickup item doesnt get destroyed. Not on server side and not on client side
Clients cannot execute server RPCs
If it tries to call it, the server will execute it only if the client has the authority over the actor you're executing the RPC on
But why its working on other classes?
Hello there, is there a way to replicate another UPROPERTY from a "FFastArraySerializer" struct, that is already replicating TArray perfectly fine? Something like this: ```c++
UPROPERTY()
TArray<FEntry> Entries; // This works great because of the NetDeltaSerialize
UPROPERTY()
int32 DummyValue = 0; // This does not replicate at all
Or wrapping it into yet another USTRUCT the only way to get it to replicate?
and how to give him authority over the actor?
I mean, the client can ask the server to execute it, but the client doesn't run the code inside of it
yeah thats right but the client should see that the server prints 2 on his screen. That how its works on every other class. It seems that he isnt sending it to the server. And I dont understand why. And even the Server cant run the destroy actor which is strange too
What is the object server RPC is in?
In the replicated Pickup Item class
Well, if the outer of the pickup is not an actor that the client owns (their player controller, their character, or their player state), the client will unable to call a server RPC, it'll simply fail, and do nothing
What do you mean with outer? Thats the structure: I call the interface event in my character and it executes the Server RPC on the pickup item
I actually meant "owner", sorry. Owner is the actor that has the ownership over a particular object. Usually, it's the actor that created the object, but it really depends on what you do.
What do you mean by "That's a structure"? You cannot call RPCs or have any events in structures, those are plain data
Hey, Is it possible to replicate data only to specific connections. I mean for example Replicate a value between Teammates
I mean how my code is structuredxD
oh, sorry 😛
Well, so you call the server RPC on your character?
i call the interface event on my character and this event get executed on the pickup item. So the character calls "Interaction" and the pickup item "On Interaction" the server RPC
npxD
will onpostlogin of gamemodeB get called after seamless travel from a map with game mode A (transition map with game mode A)?
if not what about non-seamless?
Regardless the whole chain, ultimately it's the pickup that calls the server RPC. As I stated before, you cannot call server RPCs on actors that are not owned by the client. If you want to tell something to the server, you can use the player controller or character to do that
well, thanks guys.
You were right I needed to set the owner of the actor to be the server i've find a way into my code to make just that.
Fixed a few details and stuff, and I was able to open 8 Doors at the same time, with 2 clients or 1 client and the host.
Codes were random and synched for all machines and doors openened smothly for everyone looked like a pretty solid code for an online hosted project ^^
So where would I call the pickup logic? You think I should make the server rpc on the character and cast there to the pickup item and call the pickup logic event not replicated? I thought actors exists on client and server and both should be able to execute it.
You can RPC on self-owned Actors*
If you're the client that own them
You can create a server RPC on your character, and you feed the pickup that you want to interact with, and do whatever you want. You can use the character ref that you have on the second screenshot, or maybe pass it to the function on the third screenshot
Do you mean local actors that are not replicated or what?
nono, replicated actors, where the owner is the client
just like the player character would be
Im sure that's what you ment aswell, I just read it differently 😛
figured
Ugh I'm in a bit of a mess myself with this
The back and forth just seem so... insane
Client Playercontroller TryInteract -> RPC to Server for actually Interacting -> server reaches NPC -> server reaches BP_Dialogue (a dialogue manager, of sorts) -> Informs NPC that it succeded -> Informs PlayerController that the interaction was succesfull -> RPC to Client for a local Interaction -> Reaches NPC locally -> reaches BP_Dialogue (client side) -> Gets the dialogue data....
PC(Client) -> PC(Server)->NPC(Server)->BP_Dialogue(Server)->PC(Client)->NPC(Client)->BP_Dialogue(Client)
okay so if I want a player to open a storage box, it's best to do an interaction, have the server verify it, then have the server open the storage box's inventory widget on the client that interacted? Or should the client open it
Unless there's anything to verify for the server , the client can prob just open it
server will verify / confirm any transactions from it
Gotcha! I was just worried about the client somehow opening the widget without doing the interaction
Thanks for your help!
that could be something you verified during the transact if so
just letting server check that they're actually within a reasonable range for example
That's a good idea! I already have a distance I use for interacts generally so I'll plug that in and have a go seeing if I can make it work. Thank you!
Multiplayer noob back with another question. I'm reading the Setting Up Dedicated Servers documentation and it says to start a server I have to run this command: ./Binaries/Win64/<PROJECT_NAME>Client.exe 127.0.0.1:7777 -WINDOWED -ResX=800 -ResY=450. And also another command to connect a client. Does this mean that the play button in the unreal editor is useless? Will I have to run these commands every single time I want to test something?
So, I have a dilema on how to design one thing in my building system. So, its building system based on instanced static mesh components. World is divided into chunks, e.g. like minecraft. Now, during gameplay, its easy, just send RPC to all relevant clients. But, what if player enter the chunk that already have something builded? Storing data like location and rotation for the replication would be reduntant, as this data is already stored inside ISMC. And sending it over rpcs is overall just bad idea
When doing traces for interacting/shooting/etc. is it better to do the server trace first and then the client does its own trace or does the order matter at all?
Depends on the purpose
Keep in mind, that if server is making the trace, and then sends the results to the client it takes time
So client will feel like it would have some lag
Yea, I figured for shooting it might be better to do client line trace that does the shot visually but the server is what applies damage but didn't know if that was the right approach
You are better off sending the Clients trace result to the Server. The Server can then compare its version of the trace to the Clients and then decide if they should proceed.
Gotcha, that sounds like a good approach! I'll try to implement that, thank you for the help all!
I'm not sure I properly understand this function:
https://docs.unrealengine.com/4.26/en-US/API/Runtime/Engine/GameFramework/AActor/IsNetRelevantFor/
RealViewer is a pleyer controller
ViewTarget is the actor itself, should be this?
SrcLocation is actor's location?
Checks to see if this actor is relevant for a specific network connection
why would ViewTarget be this?
UPROPERTY()
class AActor* InViewer;
/** The actor that is being directly viewed, usually a pawn. Could also be the net actor of consequence */
UPROPERTY()
class AActor* ViewTarget;
/** Where the viewer is looking from */
UPROPERTY()
FVector ViewLocation;``` comments explain everything
which you could find by searching what calls IsNetRelevantFor
So, the view target is the pawn/character, and view location is pawn's location?
static FORCEINLINE_DEBUGGABLE bool IsActorRelevantToConnection( const AActor* Actor, const TArray<FNetViewer>& ConnectionViewers )
{
for ( int32 viewerIdx = 0; viewerIdx < ConnectionViewers.Num(); viewerIdx++ )
{
if ( Actor->IsNetRelevantFor( ConnectionViewers[viewerIdx].InViewer, ConnectionViewers[viewerIdx].ViewTarget, ConnectionViewers[viewerIdx].ViewLocation ) )
{
return true;
}
}
return false;
}```
does it say Pawns location?
what if your a ThirdPerson with the camera behind the player
I was looking in documentation, usually, it has same comments :d
where would the src location be?
Camera?
yes
So the following is for the grass to bend when a player runs over it. Now, it works in single player but in multiplayer it works for no one. I don't even want it to replicate, I just want it to work for every one on their own device. How can I do that?
like this everyone can see the others bending grass but not themselves lol
How does Fast Array Replication interacts with maximum size of replication? Does it chunk it by itself, or do I need to chunk it with the RPC?
worked like this
hey guys, i'm stuck on making a simple multiplayer leaderboard, display name and score on all player widgets, i created 2 widgets (one to hold the name and score and the other has a container for all player slots), here is the code on how i made it , i followed a youtube tutorial for the replication part
the last function call there is related to the UI where it adds components and such , this code should work fine no ?
This is completely wrong
Whatever tutorial you followed was garbage
@drowsy meteor Just use the PlayerState
The GameState (which all Clients have) has a list of all PlayerStates (each Client has its own PlayerState).
Therefore you can create a Widget (such as a Scoreboard) which when opened will loop through all the PlayerStates and make a "slot" for that Player to list out its details./
any suggestions on how to make the leaderboard because i'm feeling quite blocked
