#multiplayer

1 messages · Page 86 of 1

whole pine
#

its only giving me the error cause the camera actor ref

#

do i have to cast to the level blue print or something to properly obtain the ref?

#

its weird though cause the camera was working

#

got it workin.

small grail
#

The camera ref is from the level which you put it in the map.

whole pine
#

i got actor of class and it worked

quaint roost
#

anyone else had issues with the Pawn's OnRep_PlayerState on simulated proxies?

#

like it's not being called sometimes

meager fable
#

does APlayerState::CopyProperties get called on the client?

whole pine
#

why are my players still colliding?

#

i even tried to restart the program

lean current
#

I have read about multiplayer basics, from types of servers to how they communicate with clients. Additionally, I have also made an online game using only python and got the server-client relationship to work by hosting a dedicated server. I want to do the same with unreal engine.

I have a rough prototype of a game but I can't really test much or continue development because everything depends on it being online with 2 players (most logic will have to be refactored once I make it online so I should start with it being multiplayer).

I want to make a dedicated server, and have most logic run on the server. I only use BP's.

To start; How do I create a dedicated server so that 2 players can join a server and play a simple 2D top down game?

kindred widget
meager fable
#

Yup, I've checked and the breakpoint doesn't hit 😦

#

Game instance for storing persistent client's data it is then

quaint roost
#

then you need to decide if you are going to manage the server yourself (either manually by logging into the server and opening the .exe or through some scripts)

#

or use a managed service like AWS gamelift or microsoft playfab

#

since you are starting out, just use manual deployment. your isp won't let u host on your own computer so u need something like an EC2 instance

#

gameplay side you said simple 2d top down game so it should work out of the box in terms of movement

#

after the server is up and running, open the game client, press ` and type in "open" followed by the IP address of the server

woven bramble
#

In Actor_BP, when I overlap a Box, I want the operations to run only for those who go inside that box. The "Is Locally Controlled" and branch method worked. So now the Print String is only reflected to the person who enters that box.
But when I do a visibilty operation it doesn't work. The visibilty works for everyone. I chose "Owner Only" for RepNotify, they didn't work either.
Any recommendation?

#

So let's say user 1 enters into the box, Visibilty just turns disable for him, so the system works fine. But when the 2nd user enters that box, Visibilty is opened automatically in the 1st user.

Pretty odd.

small grail
#

If you just want the visibility affects the local player, you don't even need to set it by server. Just simply local set it hidden, that's all.

woven bramble
small grail
woven bramble
#

Visibilty system works fine for local player. So it disables when I go inside, it opens when I exit, and that's what I want.
It also doesn't affect others, the system is fine and local.

But if someone else enters that box while I'm in that box, visibilty is opens for everyone.

small grail
#

For instance, I have my view and you have your view, we are different clients, is this exactly you want?

woven bramble
#

Oh, I mean this system doesn't work.

small grail
edgy helm
#

Help, my clients connecting to another player start as spectators… I tried everything I could but to no avail. Yes, I checked the start as spectator box in the gamemode but it’s inactive. The thing is I have no spawning logic, the engine has a default player pawn but it will keep spawning the spectator. Thanks in advance.

woven bramble
small grail
woven bramble
#

So not spawn

small grail
#

No spawning, no replicating, it should be like the single play game😅 The graph you said not working is?

woven bramble
small grail
#

You can make it more explicit that I just want the pawn and the pawn is local controlled.

winged badger
#

all actors placed on the level are loaded on clients from the package as long as bNetLoadOnClient is true (it is by default), and while not replicated, they are all net addressable

woven bramble
small grail
queen escarp
#

Hey Guys ok so i have an "item" on the map when a player walk close (collides) it should do stuff. the problem im having is when im colliding im casting to player player Bp from collidings actor, but it gets called on All clients Player Bp hence alot of null errors from those parts

#

how can i choose wich player bp only to cast from ?

#

to*

winged badger
#

check if its LocallyControlled

small grail
#

Yeah, feels like similar questions being asked at the same time from different channels

queen escarp
#

well it felt more like a multiplayer room question hence i dident get any answer from the other channel 😛

#

how do i check if its locally controlled

small grail
#

drag it from pawn and search is local controlled.

queen escarp
#

from other actor ?

#

or

#

something like this :/ ?

#

hmm seems to work 😄

#

also when destroying Actor it still leaves the collision in world do i need to destroy the actor on the server only or also ?

#

like why is this happening ?

kindred widget
queen escarp
#

erhm ok,

#

cuz mine wont dissapear

#

or it dissapears but hte collision is still there :/ ?

small grail
queen escarp
#

oh its the is locally controlled thats whats messing with it

radiant dew
queen escarp
#

actualy no i was just destroying it localy

#

@radiant dew

radiant dew
#

oh yeah true

whole pine
#

in my topdown game, i dont want my mouse to click through a player capsule i disabled overlay events and made collision query only but it still lets the click go through the capsule when i click a player and my character starts running to them

rapid sky
#

Hey Guys, I have a weird issue with blendspace locomotion animations. When i test it in editor all works perfect and when testing via steam the server sees the client animations slower, like, way slower! Although the velocity values are the same. tested it via print string, i dont have a clue anymore whats the issue. Anyone stumbled upon this?

thin stratus
sage light
#

Hi guys, is the dedicated server optimized by default to only compute relevant things?
For example, if I have built the server and it is on my AWS, is it also going to waste computing power on simulating physics, and so on?

prisma snow
sage light
#

by the way the ball isn't replicated if that matters, the simulation runs on each machine

prisma snow
#

Valorant run at 120Hz iirc, but I can imagine that needed lots of work

sage light
oak pond
#

if Im doing the steam listen server method, is there any way to set up a play test without it being published on steam?

sage light
#

I thought that the async tick is irrelevant to the server, isn't only the replication tick relevant for the server?

prisma snow
sage light
#

It's a VR game so the client does the collision detection and updates the server about the hit

#

the server is not deciding on the hits, the ball isn't replicated

#

but I'm not sure if the server will simulate how the ball moves just like the other clients do

prisma snow
#

Somebody with experience in multiplayer physics should jump in but I'd asume server runs physics too

chrome bay
#

It does

#

Why aren't you just substepping instead of trying to run the game at over 600Hz?

prisma snow
prisma snow
oak pond
#

are there any good tutorials for settings up hosting with steam, every one I can find is a real mess

oak pond
cinder quartz
#

I was hoping that 5.2 will fix it, but it didn't so haven't looked what causes it yet...

rapid sky
#

Oh, wow! Well, it makes sense i couldnt find any help with the problem, seems to be a new one. Sadly, i didnt find any fix yet, also.

thin stratus
#

@rapid sky @cinder quartz again this has been a thing for a very long time

#

ListenServer doesn't tick anims for simulated clients. It only updates them when a Move comes in via RPC

#

There is some location smoothing iirc but I don't think the anims are smoothed

cinder quartz
#

No, this is different. Client animations are running in slow motion, like play rate 0.5, baywatch running and it didnt happen in 4.26, 4.27 or 5.0

thin stratus
#

You need to change a few things and override some CMC function to get this to happen on tick

#

Hm. Okay

cinder quartz
#

for me it started happening when going 5.0 -> 5.1. the choppiness was always there for listen server, but the lowered play rate wasnt

#

tho it seems to work correctly when not simulating lag, so no idea why it is like that

#

more ping = more slowness

rapid sky
cinder quartz
#

just tested on fresh, new 3rd person template 5.2 version. Also happens there when enabling network emulation with bad condition, the client is running on slow motion on hosts screen

cinder quartz
fathom aspen
#

@cinder quartz

#

This linked reddit thread

oak pond
#

I just set up hosting and joining in my project, now how would I go about testing that with someone else? as far as I know its gonna need steam or something right

cinder quartz
# fathom aspen This linked reddit thread

Thanks. The comment says in ACharacter::PossessedBy "If we are controlled remotely, set animation timing to be driven by client's network updates. So timing and events remain in sync.". Why does listen server need special things to stay on sync but dedicated server doesnt? Animation events will still fire on dedicated server right?

meager spade
#

dedicated server does not play animations

#

listenserver does

#

there is no visual rendering

cinder quartz
#

it still has to keep track when animation events fire?

meager spade
#

yes it runs the events

#

but it doesn't do any rendering

#

so it doesn't need to be as precise

#

its weird, but it is what it is

cinder quartz
#

oh so the comment just means "keep visuals and events in sync"

meager spade
#

yes

cinder quartz
#

kinda strange it isnt a toggle in engine, I mean the fix is 5 year old and still applies lol

meager spade
#

we hit many pitfalls with listen server

#

but we solved a lot of the animation issues like the slow mo

cinder quartz
#

would it be practical to start dedicated server in the background and connect to it?

meager spade
#

if your game is going to use dedicated servers

#

just use play as client in the editor

#

it will spin up a dedi server

cinder quartz
#

I mean in a released game, let's say I want my game to be multiplayer with steam friends, but don't want it to be listen server. So If I start a game, my game would start a dedicated server and join it locally and invite my friend to it

meager spade
#

no

#

your friend or you would need to launch the dedi server

#

then you connect your clients

#

to that server

cinder quartz
#

is there any other know issues to listen servers other than animations?

meager spade
#

for a small game, its easier just to run listen servers

#

dedicated servers is a big thing

#

not really

#

i mean sure there is some nuances, doing dedicated server stuff is easier for mp

#

listen server, you need to ensure stuff happens correctly, else things break (like doing x on the client but forgetting the server)

#

like playing montages, etc

#

then you have the fact listen server has all client, so things like GetPlayerCharacter static is a no no

cinder quartz
#

I can confirm that the reddit fix fixes the animation play rate issue.. and those smooth listen server animations look great!

fierce fiber
#

I'm not too sure If I'm going about this in the right way, but Im trying to create a respawn mechanic where the player can pick up a cube, take it to a respawn point and the dead player will respawn, currently struggling on the first hurdle of the player picking up their respawn cube, so what I've done is I've stated in the First Person Player blueprint, when dead, spawn the cube and store their player controller, here is an image of that in action:

#

I've then stored that information on the respawn cube from the spawn node:

#

At this point, it works, the text above the cube shows the name of the player who it belongs to, Then I use a line trace to pickup the cube and store the players controller inside a variable in the FPS controller, but for some reason on the print string, it prints nothing, as if nothing is being stored in that controller

#

If anyone has any experience in multiplayer and can guide me in the right direction that would be a huge help

queen escarp
#

Question about RPCing

if this is a variable and that variable is replicated how do i need to tell the sercer/other clients when the value is changing

#

do i need to cast to server>multicast and then set the change

#

or just server or

#

could someone explain really simple why/how

dark edge
queen escarp
#

Ok so multicasting is only for sounds speciall effects basicly ?

dark edge
#

Replicated variables with RepNotify are super powerful. Learn them and use them.

icy jetty
#

I was gonna say, he needs to use set w/ notify tho, right ?

dark edge
#

Depends on if you need some logic to run whenever it changes

#

Sometimes you do, sometimes you don't

queen escarp
#

Repnptify gotcha ill look into it

icy jetty
oak pond
#

is it even possible to use their servers on a game that’s not published there yet?

fierce fiber
dark edge
#

What is the player "driving" when they are dead?

fierce fiber
#

This all happens when the players health reaches 0

#

Once it reaches 0, Spect_Mode is called

dark edge
#

just call RestartPlayer or do the equivelent when they bring the cube to the thing

dark edge
#

Hey mr gamemode, i died xd, give me the ghost pawn now plz

fierce fiber
#

Ah I see

#

Also

#

How will the cube know to bring that player back when they deliver it to whereever

queen escarp
#

@dark edgein case of changing the bool on server do i need to change it localy also or only on server ?

dark edge
#

server sets it, everyone else gets it updated automagically

queen escarp
#

ah ok

icy jetty
#

That trigger a function within that player’s bp

#

If ded 💀 and cube is touching me 🤚, bring me back to life

#

At least, in theory😅

fierce fiber
#

Oh yeah, why didnt I think of it that way haha

outer sphinx
#

Hello guys how are you doing? I have a question I want the server to know what is the value of the variable "attack anim1" which obtains its value from a struct. I replicated the variable and also RPCed the function where it gets the value. What am I doing wrong or what can I do to fix it? thank you so much.

woven bramble
waxen socket
#

Hello. I have a question about movement replication for anyone who can help.

On the server, I'm using the AddActorLocalOffset node. Now, despite ReplicateMovement being unchecked, this movement is still visible on the client. 🤔

Does anyone know how movement could be replicated without ReplicateMovement being checked?

Any advice would be appreciated. 🙂

Cheers.

fathom aspen
#

On the server
doubt

#

How do you know you're on the server?

#

And how does the actor get spawned? Is it just a plain actor? or a character with a CMC?

waxen socket
oak pond
#

how do you play test a project with other people before its published? if Im using the steam method, wouldnt it need to be published or something?

plucky prawn
oak pond
#

wdym

quasi tide
#

Upload it to steam. Give your team dev keys or other people playtest keys.

quartz smelt
# oak pond wdym

you don't need to publish it, you can playtest it as long as everyone as a steam account (and it works properly)

oak pond
#

ah nice

#

Ive set up the joining and hosting already, but how do I get that to use steam?

quartz smelt
#

if you have it setup properly, and have the steam subsystem enabled correctly, you should be able to host and join with no issues

oak pond
#

I used the default session nodes but not sure what the steam thing is since I enable the plugin but dont know what next

#

somehow I remember getting the overlay working years ago

quartz smelt
#

theres something in the .engine or that you have to add to enable the subsystem. Cant remember it off the top of my head though

oak pond
quartz smelt
#

yeah that's it

oak pond
#

ngl I dont understand any of this

#

idk where Im supposed to start

quartz smelt
#

I recommend watching some tutorials, multiplayer is a tough process

oak pond
#

yeah as I said earlier all the tutorials are a mess

#

joining and hosting works on the same network already

quartz smelt
#

If you have everything in the .engine, and the steam subsystem plugin enabled, then the issue is your blueprints

#

once you have those 3 things working, you'll package the project and have everyone test it out

oak pond
#

no I havent even gotten to that stage because apparently I have to set up the whole steam page now or something

quartz smelt
#

No you don't need to set up a steam page

#

You'd send the packaged project to your friends, and they'd open the game up from the file

oak pond
#

I know but I cant see any other way to access the thing I need to download

quartz smelt
#

What're you trying to download?

oak pond
quartz smelt
oak pond
#

so where would I get what I need for the rest of whats on this page

quartz smelt
#

scroll down to "finished settings"
you can copy that, its the basic stuff of what you'll need for playtesting

oak pond
#

is steam overlay supposed to work after doing that

#

just a sec

quartz smelt
#

yes and no

#

the steam overlay will work in standalone

oak pond
#

yeah I thought that

quartz smelt
#

you'll also need to restart your ue4

#

or 5

oak pond
#

my defaultengine ini has a lot of stuff already so do I take all of that out?

quartz smelt
#

no

#

Add it to the stuff already there

oak pond
#

yeah nothing

quartz smelt
#

and this is enabled?

oak pond
#

yeah

quartz smelt
#

Try exporting the project and launching it from the file exported

#

if that doesn't work, create a blank project and just add .engine stuff + subsytem

oak pond
#

ah yeah, works in the packaged game

#

Im sure I remember it working in standalone before

quartz smelt
#

oh wait

#

check the advanced settings and make sure it looks like this

oak pond
#

wheres that

quartz smelt
#

on the dropdown to select in editor, standalone, etc its at the bottom

oak pond
#

I looked there but I dont have those options

quartz smelt
#

Did you select advanced settings

oak pond
#

would it be this

quartz smelt
#

thats

#

weird

#

what version of ue4 are you on

oak pond
#

4.26

quartz smelt
#

Try searching up "auto connect" in the search bar up at the top

oak pond
#

just this

quartz smelt
#

That's weird, I'm using 4.22

#

this enabled too?

oak pond
#

yeah, overlay shows in packaged game but also now it cant start a server

quartz smelt
#

In this video we take a look at the finished project and step through each of the features that will be covered in this series. We show our functional Main Menu and its options, a lobby where players can chat with one another and select their characters for the game, some server options such as changing the map or match time as well as the abili...

▶ Play video
#

here follow these vids, theyre very simple

#

try making a basic host/join project before you do anything big

oak pond
#

I did, I just said that already works on the same network, I can join "myself"

#

just not now that its using steam

quartz smelt
#

It could also be something with your blueprints too

oak pond
#

are there not steam specific nodes?

quartz smelt
#

not necessarily steam specific I think

#

you're using bp yeah?
The basic "host session" "join session" "find session" should work for you

oak pond
#

oh, it DOES let me host now? a minute ago it was doing nothing

#

I assume you cant connect to yourself with steam though?

meager spade
#

no

#

you need another machine to connect to you

#

with a different steam account

oak pond
#

ok thanks for the help guys, Ill see how it goes now

meager spade
#

so you either run a server or run the client iirc

#

its a bit shit

#

maybe you can run the server and client together, but i gave up with steam a while ago (steam's backend)

#

EOS is the way forward

quartz smelt
#

Multiplayer overall is a beast to take on, make sure you've got some knowledge of bps before you start a multiplayer project

#

it'll stunt your growth

meager spade
#

and c++ if your making a true multiplayer game

#

with beacons, etc

oak pond
#

played around with a little bit of replication once

meager spade
#

longer than me 😉

#

im at 5 years

oak pond
#

oh wow

meager spade
#

i started game dev 5 years ago

quartz smelt
#

Oh nah you'll be fine then. I think ue5 is good for multiplayer right? -- might be wrong though, heard some good things

meager spade
#

at the ripe age of 32 😛

oak pond
#

I imagine ue5 would be overkill for this game, graphics are cartoony and Im hoping to optimise it well

meager spade
#

it's got some nice stuff though

#

in uje5

oak pond
#

yeah Id like to try someday, but I dont even have the space for it right now actually, and not sure anything I make will need such a huge engine

fringe dove
quartz smelt
fringe dove
icy jetty
lost inlet
#

that link really explains very little about Iris

quasi tide
#

If you're struggling with current networking for Unreal, don't even think about Iris.

round acorn
#

This variable (array of structs) is set to replicate but inside a spot where I need it to replicate it says "None"

sinful tree
round acorn
#

Ah, roger... wish it would say it's replicated at least.

#

Having the strangest issue where the array is not replicating, or does not appear to be

#

the server's version of the array has the item, but the client never receives that version

#

then when I transfer to my inventory it's like, oh... yeah here you go

#

The client somehow knows items were made and they show up in the inventory as essentially blank items, but of the correct type

#

all the client is receiving is the very basic slot struct, not the rest of the item

#

til I drag/click to add to my inventory

#

This right here is where I am somehow not able to replicate the "Item Struct" to the Inventory Content array

#

Set Array Elem is setting Item Type, Item ID and Quantity but that struct is left behind

icy jetty
#

@round acorn was it you that was doing a damage numbers widget over an actor’s head a while back ? Sorry to derail 😅

round acorn
#

I dunno what's up with this but when I multicast the update to the inventory content array it works fine... why can't I just rely on the server replicating the values to the clients?

#

erm, yeah I did that a long time ago

round acorn
#

naw just replicated

thin stratus
#

For sanity, set the array* with itself after calling the set array element node

round acorn
#

Curious, what does that do?

thin stratus
#

Maybe fix your issue. I had issues in the past with some of the array altering nodes not triggering certain replication features. It's mostly the OnRep part, hence the question, but can't hurt trying

round acorn
#

k let's give that a whirl, sec

#

maybe just like this?

thin stratus
#

Yes

storm zinc
#

Ok so odd question here. I have requested an API for some data, on the dedicated server, and I am firing an event on the client. That part is working, however, the data I am passing back to the client is null. Is there some 'replication' thing that I should be aware of? I am trying to send a VaRest Json Object to the client. Or should I just move the request to the client instead?

thin stratus
#

At least for OnRep it solves the issue of not causing the OnRep call

#

I assume some code is tied to the Set node that the other nodes don't cause

#

In BPs that is

round acorn
#

no dice, but multicasting the Set Array Elem works just fine... I don't get it

thin stratus
#

Hmpf. Sorry. Hoped it was a similar issue

thin stratus
round acorn
#

Is there a way to tell if I am exceeding the max bunch size on replication?

thin stratus
#

Try sending the JSON as a string instead @storm zinc

#

Logs I would assume @round acorn

storm zinc
round acorn
#

assuming that would be a warning or an error, not seeing anything re: that

thin stratus
#

@round acorn so you have any conditions on that array replication?

round acorn
#

no conditions

thin stratus
#

If you tick the UI refresh on the client, does it then start working?

#

Maybe some sort of race condition?

round acorn
#

that was what I thought too but no, it stays the same... til I run the function to take an item from the container inventory to the player inventory and then the server gives me the item in all its glory

thin stratus
#

Hm sorry, not sure the at then moment. 🥲

#

Will head back to bed. Woke up from some random a** nightmare. Hope you figure it out. Probably something small.

storm zinc
#

Also, it helps if you attach the json object to the Call Url function ^.^

#

sigh

round acorn
sinful tree
round acorn
#

haha yeah a few times

sinful tree
#

How are you relying on your UI to update in general? Are you using binds to read the data from the inventory?

round acorn
#

binds yeah

#

but I print stringed the client's copy of that inventory array and it was empty

#

I mean wtf... it's set to replicate and it's just not replicating

#

it's running on a Server RPC and I've confirmed the RPC is executing

oak pond
fathom aspen
oak pond
#

got my friend to open it and we both tried hosting and nope nothing shows up

round acorn
#

I'm doing this updating of the array from a different place though, the Item Data Component

#

(which is a component owned by the same actor that owns the inventory system component)

fathom aspen
#

It doesn't really matter, as long as the original outers replicate you're fine

round acorn
#

I tried serializing the whole thing to see if I was overloading the network but that made no difference

fathom aspen
#

I vaguely remember a very odd issue of having only 1 property in a component doesn't really replicate that property

#

But adding another property will make it replicate

oak pond
#

ah I almost forgot how much of multiplayer is "why doesnt this thing work when I literally went through every step"

fathom aspen
#

Not sure if the other property needs to replicate or not (most probably yes)

#

And it's really odd and even rare?

#

Never happened to me

#

Maybe because I don't have components with 1 replicated property?

round acorn
#

My Inventory System Component has 4 or 5 replicated properties (prolly 4 of them aren't actually being used though lol)

fathom aspen
#

Yeah maybe it has to be set even

round acorn
#

Because I tried making a new property and using that instead (didn't work of course)

fathom aspen
#

Not really sure about the specifics

#

But you can try it

#

Literally a boolean that you set to true on beginplay

#

And that it replicates ofc

meager spade
#

there is a bug where property replication fails

round acorn
#

oh set replicates specifically

meager spade
#

with 1 replicated property

fathom aspen
#

Okay here's the confirmation

#

Thanks Kaos

meager spade
#

one of our bools 😉

round acorn
#

lol

fathom aspen
#

🤣

#

Press F for bandwidth

round acorn
#

not sure I understand the way this bug manifests

oak pond
#

so is there anything specific that I need to add for steam servers? hosting and joining myself works without it I set that up

round acorn
#

you have a component on an actor and the component has one, and only one, replicated property? and that fails?

meager spade
#

yes

#

we experienced this with 1 replicated prop

#

where replication would be, lets say, intermittent

oak pond
round acorn
#

interesting that I think I'm only actually using 1 replicated property here on this component (there are others but they aren't in use)

oak pond
#

but in the packaged project it uses steam and nothing happens

icy jetty
fathom aspen
#

Do you need to set that replicated property you added at runtime? Or you don't need to? @meager spade

#

So for example EpicFailsAgain=false

round acorn
#

that wouldn't necessarily look like this, for us BP plebs?

fathom aspen
#

Nah

round acorn
#

that's inside my inv sys comp

fathom aspen
#

We are talking properties

#

Not the instance

round acorn
#

I mean, I just added it, it wasn't there 5 mins ago. Aye properties

icy jetty
fathom aspen
round acorn
#

Was it resolvable by adding another replicated property into the component (e.g. that bool)?

fathom aspen
#

Yeah

#

Is it for you?

round acorn
#

I'm gonna try that even though I already have a couple other replicated properties, gonna do some experiments

#

lol editor crashed when I deleted a variable with 0 references project wide

#

gotta love it

#

Is there anything wrong with calling a function within a Server RPC?

quasi tide
#

No?

round acorn
#

I'm doing Server_GenerateLoot (RPC) and within that calling Generate Loot, which is a function in that actor's event graph.

quasi tide
#

That's the flow

round acorn
#

And it does a lot of random generation in there, server side. Stores all of that in a struct, inside a struct, with quite a few other structs inside that even.

quasi tide
#

Doesn't matter

#

Server RPC is running on the server

#

That data you pass is what actually transmits across the wire

round acorn
#

If I update the Array of Structs in that server RPC I shouldn't need to pass it anywhere though right? It's set to be a replicated property.

quasi tide
#

So anything after the execution pin is running on the server

round acorn
#

I mean, the Server does indeed get passed the correct array of structs

#

the right instance

#

And it updates the value in there in that Generate Loot function

#

And I would think it should just replicate from within the Server RPC

#

Is that just... not the way it works?

#

Because when I pass this new item to the Multicast it works like a charm

latent heart
#

Replicate from within the RPC? No. It may change a va lue on the server and that will eventually be replicated to clients.

#

But it is in no way instant.

round acorn
#

If the server updates its copy of a replicated variable doesn't it immediately (like within a few frames... maybe a second or two) start trying to update client versions?

#

(Granted, there's always lag to consider)

latent heart
#
  • Client tells server "hey, here's a value" using an RPC (because replication doesn't work client to server)
  • Server checks value and updates its settings
  • Server then either (or maybe both):
    • Uses regular replication to update the clients (eventually) about this change (99.9999% of cases)
    • Sends a multicast rpc to immediately inform clients of an important change (0.0001% of cases)
round acorn
#

Makes sense, and what I understood

#

But I'm waiting several seconds and this data is not replicating, but with a multicast it replicates instantly

#

(well, close enough)

latent heart
#

The replication part isn't instant. Property updates are queued and sent based on priority.

#

It shouldn't take a few seconds, though.

round acorn
#

Right but it's just... never getting there

latent heart
#

Is the property actually set to replicate?

round acorn
#

Yep

#

And the component

latent heart
#

BP or c++?

round acorn
#

BP

latent heart
#

Is the component set to replicate? Do other properties on the component update?

round acorn
#

yeah the component is... other properties, not sure. I believe a repnotify is working for sure

latent heart
#

Repnotify... of what?

round acorn
#

full inventory transfer completion

latent heart
#

What I mean is, if repnotify is triggering then something is replicating. What is it and what object is it on? Is it on the component that should be updated with this troublesome value?

round acorn
#

I just built a little test to see if the component is replicating

#

and it's... not working in one instance

latent heart
#

Meaning?

round acorn
#

not sure which instance of this component yet, but one of them (of 4) is not receiving a replicated bool

latent heart
#

Are you creating any of them on the client?

#

Like creating them at runtime instead of at design time?

round acorn
#

mmm, no not on this testing I don't think

latent heart
#

Be sure 🙂

round acorn
#

oh lol hmm

#

this might be an issue

#

4 instances of the component

#

3/4 are getting the server replication of the bool

#

1/4 is not, the top one

latent heart
#

They don't look like components.

round acorn
#

those are the owners of the componnent

#

bottom two are actors, chests

latent heart
#

Also PlayerStateCharacter is... a bad name.

round acorn
#

okay so that 1/4 false was a pawn that I'm loading from a level instance to do my character preview (it's a janky test setup)

#

so that wasn't the issue

latent heart
#

Okay.

#

If it's a character preview, it shouldn't be on the server, surely?

#

It's just client side visualisation?

round acorn
#

like I said, it's janky lol

#

yeah

#

I just dropped my character BP into the level for testing of the camera setup

latent heart
#

Ah okay.

round acorn
#

Component is definitely replicating

amber barn
#

hi guys, im using server travel to move my host and clients from the lobby to the main map but i get this error, i thought I was doing this right

I type Host into console and get the error in the picture, doesnt work when running the game standalone if i run in editor, works fine, i move levels with no problem.

the code runs as i can see the prints on the screen

sorry to interrupt the above convo

relevant code:

void UPuzzleGameInstance::Host()
{
    UEngine* Engine = GetEngine();
    if (!ensure(Engine != nullptr)) return;
    Engine->AddOnScreenDebugMessage(0, 10, FColor::Green, TEXT("Hosting"));

    UWorld * World = GetWorld();
    if (!ensure(World != nullptr)) return;
    Engine->AddOnScreenDebugMessage(0, 10, FColor::Green, TEXT("Changing maps"));
    World->ServerTravel("/Game/ThirdPerson/Maps/ThirdPersonMap?listen");
}
latent heart
latent heart
amber barn
latent heart
#

It's likely that level just isn't being packaged.

#

A text-based link like that in c++ does not mean the map will be packaged.

#

You should add it to the list of maps to be packaged in your packaging settings.

amber barn
#

hmm ok, ahh ok just to confirm this is how u package?

latent heart
#

I would say so, yes.

#

The packaging settings might not be there, but in your project settings.

amber barn
#

yepyep

latent heart
amber barn
#

oh sorry that channel wasnt even in my list

#

thank you

deep coral
#

does client authoritative movement work for pawns that are owned by the client but not possessed?

quaint roost
#

does anyone know the bottleneck for scale when replicating a lot of attributes in PlayerState (like in the default GAS setup)?

is it server CPU/mem, server kbps out, client kbps in?

#

i currently have a GAS on playerstate, which replicates all player attributes to all players (since playerstate is always relevant)

#

and im planning for 20 players in my game

#

was wondering if to support 20 players i can just get a bigger instance

#

instead of using a replication proxy

latent heart
#

You could have a thousand players and probably not have a memory issue.

#

The important part is how often those values change, not how many there are.

fossil spoke
#

CPU is likely going to be the limiting factor here.

#

But as with anything else performance related, you really need to profile it.

meager spade
#

^

fossil spoke
#

As performance encapsulates everything.

meager spade
#

Memory is never usually the issue with dedi servers

#

(well normally)

fossil spoke
#

Sure you can target specific parts, but its only going to be in relation to the whole.

#

Profile, optimize, profile again.

meager spade
#

i mean with memory side of things, just ensure the dedi server isnt't loading things its never going to use or need to use

small grail
#

If you are using gamelift or the service like that, you can save money as well if manage these kinda of data transferring smartly😛

spark pelican
#

Im working on respawning the pawn after death. In the Gamemode I am creating a new pawn and on the controller calling Possess(). Where on the new pawn can I run code post possess. I tried in PossessedBy() however this gets called before the controller does SetPawn and this messes some thing up for me. Is there any other function that gets called?

latent heart
#

OnPossess?

#

There's also ClientAcknowledgePossession or some such.

#

You'll have to look for the specific function.

fossil spoke
small grail
daring arch
#

Hiya!

Is there any way to apply force to CMC in a way that doesnt break clientside prediction?

latent heart
#

Physics is always going to break clientside prediction 😛

#

That's just a facetious reply, don't worry. 🙂

daring arch
#

thought so- then, if i want to add any sort of movement that is not already native to CMC, i'll have to roll my own solution with my own clientside prediction?

latent heart
#

You can add your own custom movement modes to the CMC.

#

I have zero experience in that (or the CMC in general) though.

daring arch
#

Thanks for the info!

latent heart
#

np

fossil spoke
#

Check the pinned messages in this channel.

latent heart
#

I was just about to say there's bound to be tutorials!

fossil spoke
#

There are plenty of resources on how to add your own advanced mvoement modes to the CMC

#

Mind you, they can get complicated.

#

As the CMC is no walk in the park.

latent heart
#

The CMC is a bloated mess of horribleness you mean! 🙂

quasi tide
#

Need to keep with the theme!

amber barn
#

hi guys, im trying to allow my players to set their name via a console command, it works but only works for the clients

viewport game is the listen server/client

the game in the small window is my client

the viewport game ran the command to set the name

im doing something similar for health, just setting health on the server side and it replicates to all clients but on the widget im using the native tick function

my understanding was taht if you run code outside IsLocallyControlled and GetLocalRole() == ROLE_Authority it runs on both clients and servers and but it doesnt seem to function that way

  • sorry for the ant sized text
void APlayerPawn::OnHealthUpdate()
{
    //Client-specific functionality
    if (IsLocallyControlled())
    {
    }

    //Server-specific functionality
    if (GetLocalRole() == ROLE_Authority)
    {
        if (CurrentHealth <= 0)
        {
            bIsDead = true;
            APlayerStateWarlocks* PlayerStateWarlocks = Cast<APlayerStateWarlocks>(GetPlayerState());
            if (PlayerStateWarlocks != nullptr)
            {
                PlayerStateWarlocks->SetIsPlayerPawnDead(true);
            }
            Destroy();
        }
    }
}

void UHealthBar::NativeTick( const FGeometry& MyGeometry, float InDeltaTime )
{
    Super::NativeTick( MyGeometry, InDeltaTime );

    if ( !Owner.IsValid() )
        return;

    HealthBar->SetPercent( Owner->GetCurrentHealth() / Owner->GetMaxHealth() );

    FNumberFormattingOptions Opts;
    Opts.SetMaximumFractionalDigits( 0 );
    CurrentHealthLabel->SetText( FText::AsNumber( Owner->GetCurrentHealth(), &Opts ) );
    MaxHealthLabel->SetText( FText::AsNumber( Owner->GetMaxHealth(), &Opts ) );
}

void APlayerPawn::OnPlayerNameUpdate()
{
    if (GetLocalRole() == ROLE_Authority)
    {
        // UPlayerName* PlayerNameLabel = Cast<UPlayerName>( PlayerNameWidgetComp->GetUserWidgetObject() );
        // PlayerNameLabel->SetName( PlayerName );
        // // ue log player name
        // UE_LOG(LogTemp, Warning, TEXT("PlayerName: %s"), *PlayerName);
    }

    UPlayerName* PlayerNameLabel = Cast<UPlayerName>( PlayerNameWidgetComp->GetUserWidgetObject() );
    PlayerNameLabel->SetName( PlayerName );
    // ue log player name
    UE_LOG(LogTemp, Warning, TEXT("PlayerName: %s"), *PlayerName);
}
sinful tree
amber barn
sinful tree
#

You may see it locally as clients can change their variables as they like, but in order for it to be replicated to everyone else, it must be set on the server, and any value you want the server to know about must be passed through an RPC.

amber barn
# sinful tree You may see it locally as clients can change their variables as they like, but i...

hmm ok
my command is this

void UPuzzleGameInstance::SetPlayerName(const FString& PlayerName)
{
    APlayerController* PlayerController = GetFirstLocalPlayerController();
    if (!ensure(PlayerController != nullptr)) return;
    PlayerController->PlayerState->SetPlayerName(PlayerName);

    // get the actor and set the name
    APlayerPawn* PlayerPawn = Cast<APlayerPawn>(PlayerController->GetPawn());
    if (!ensure(PlayerPawn != nullptr)) return;
    PlayerPawn->SetPlayerName(PlayerName);
}

my understanding is that the onrep would run

    UPROPERTY(ReplicatedUsing = OnRep_PlayerName)
    FString PlayerName;

but youre saying the command is local/on the client so the server doesnt know and therefore on rep doesnt run

#

is that about right?

sinful tree
#

Correct.

amber barn
#

so i gotta RPC the setting of the name

sinful tree
#

You need to RPC that you want the player's name to change, then have the server set it. Once the server sets it, the OnRep should fire on clients when they receive the change.

amber barn
#

ok thanks outof these two... i wanna do the second one?

#

i take it you cant* do it like this

    UFUNCTION(Exec, Server)
    void SetPlayerName(const FString& PlayerName);
sinful tree
#

Yep.
You may also want to do some sanity checks on the name before setting it too, like make sure it's not too long, not too short, etc.

amber barn
#

sorry i edited my comment, can or cant you? cause i got a red underline haha

#

bah im silly

sinful tree
#

Oh oops, uh should just be UFUNCTION( Server )

amber barn
#

ya i can just have two functions

sinful tree
#

Then you also need to use this when defining the function in order to actually set on the server.

SetPlayerName_Implementation(const FString& PlayerName) 
#

Also... It can't be done in the game instance.

#

It probably should be in the PlayerState.

amber barn
sinful tree
#

You can store the name locally in the game instance, but you must pass it to the server on a replicated actor that is owned by the client - playerstate makes sense since you're dealing with playerstate data anyway.

amber barn
#

yep makes sense

amber barn
#

forced me to add reliable

    UFUNCTION(Server, Reliable, WithValidation)
    void SetPlayerName(const FString& S) override;
#

validation just mean what you said before? here is where i check if too long etc and return false if it's doesnt fit the criteria?

thin stratus
#

No one uses the Validate function. Just return true. If you return false it will kick the client that tried to send the RPC iirc

#

Also, the GameMode has a ChangeName function. Once you are on the Server side with your RPC it's probably best to just call that

amber barn
small grail
#

Validation is just for something anti cheating. If you are running a listen server, it doesn't really need to do

amber barn
#

hmmm so

void UPuzzleGameInstance::SetPlayerName(const FString& PlayerName)
{
    APlayerController* PlayerController = GetFirstLocalPlayerController();
    if (!ensure(PlayerController != nullptr)) return;
    PlayerController->PlayerState->SetPlayerName(PlayerName);

    // get the player state warlocks
    APlayerStateWarlocks* PlayerStateWarlocks = Cast<APlayerStateWarlocks>(PlayerController->PlayerState);
    if (!ensure(PlayerStateWarlocks != nullptr)) return;
    PlayerStateWarlocks->SetPlayerName(PlayerName);
}

this is working..

      UFUNCTION(Server, Reliable, WithValidation)
    virtual void SetPlayerName(const FString& S) override;

void APlayerStateWarlocks::SetPlayerName_Implementation(const FString& S)
{
    // get player pawn and set name
    APlayerPawn* PlayerPawn = Cast<APlayerPawn>(GetPawn());
    if (PlayerPawn)
    {
        // log to see if running
        UE_LOG(LogTemp, Warning, TEXT("PlayerName: %s"), *S);
        PlayerPawn->SetPlayerName(S);
    }
}

this is working and printing..

but the name wont change in the UI, the code below isnt running either

void APlayerPawn::OnPlayerNameUpdate()
{
    if (GetLocalRole() == ROLE_Authority)
    {
        UPlayerName* PlayerNameLabel = Cast<UPlayerName>( PlayerNameWidgetComp->GetUserWidgetObject() );
        PlayerNameLabel->SetName( PlayerName );
        // ue log player name
        UE_LOG(LogTemp, Warning, TEXT("PlayerName: %s"), *PlayerName);
    }
}
amber barn
small grail
sinful tree
#

Exception would be if this is running on a client spawned actor.

small grail
#

The thing you need to do is set the name variable replicated and OnRep event to change the name for your clients.

amber barn
#

think mm yep makes sense

so when... the name changes for client x i want to change the name in theui for all the clients so just do it for all clients not on the server

#

yeah of course! that makes sense

sinful tree
#

Additionally, you're setting the playername on the playerstate. Why would the OnPlayerNameUpdate() run on your pawn?

amber barn
#

ahh im so confused now

sinful tree
#

The UI should just reference the playerstate 😉

amber barn
#

mmmm

#

that is so much better

#

so fuck off all the pawn code for player name and just get the UI widget to check the player state for the name

sinful tree
#

Basically. If the name tag will only ever be used on player characters.

amber barn
#

how do i trigger the ui to get the player name, though? there is the tick function... but... seems heavy handed

sinful tree
#

Well, you could create a delegate in your playerstate that you broadcast when the OnRep is fired.
On Construct of the widget, you can get PlayerState, cast to your custom playerstate, bind to the delegate, and also read the current value.

#

Bindings are simple enough, but those act like tick too.

thin stratus
#

You might have a race condition though between Character and PlayerState. You will need to make use of the OnRep_PlayerState function of the Pawn to ensure the PlayerState is valid when the UI spawns

sinful tree
#

Multiplayer is so much fun.

thin stratus
#

Yus. Can be happy they use cpp

#

We usually have a parent widget that has the whole "Is my Pawn and PlayerState valid?" System setup and just provides a function when everything is valid and available for child classes.

amber barn
#

haha i had that in a dota mod i did for the exact same reason

thin stratus
#

That's for HUD but would work very similar for a WidgetComponent widget

amber barn
#

alright thanks guys, i wont bother you anymore ill have a tinker

thin stratus
#

Just keep in mind that if you work with more than one replicated actor that it's best to ensure one doesn't exist before the other. Here that's character vs PlayerState

amber barn
small grail
quasi tide
#

It does

amber barn
amber barn
#

bah, im getting the same behaviour as before, i switched to doing it all on the widget and player state but again the client shows the change and the listen server doesnt

void APlayerStateWarlocks::SetPlayerName_Implementation(const FString& S)
{
    PlayerName = S;
}

bool APlayerStateWarlocks::SetPlayerName_Validate(const FString& S)
{
    return true;
}

void APlayerStateWarlocks::SetPlayerNameWidget(UPlayerName* pnw)
{
    PlayerNameWidget = pnw;
}

void APlayerStateWarlocks::SetPlayerNameOnPlayerWidget()
{
    APlayerPawn* PlayerPawn = Cast<APlayerPawn>(GetPawn());
    if (!PlayerPawn) {return;}
    if (!PlayerNameWidget){return;}
    
    UE_LOG(LogTemp, Warning, TEXT("PlayerName: %s"), *PlayerName);
    PlayerNameWidget->SetName(PlayerName);
}

void APlayerStateWarlocks::OnRep_PlayerNameCustom()
{
    SetPlayerNameOnPlayerWidget();
}

void UPuzzleGameInstance::SetPlayerName(const FString& PlayerName)
{
    APlayerController* PlayerController = GetFirstLocalPlayerController();
    if (!ensure(PlayerController != nullptr)) return;
    PlayerController->PlayerState->SetPlayerName(PlayerName);

    // get the player state warlocks
    APlayerStateWarlocks* PlayerStateWarlocks = Cast<APlayerStateWarlocks>(PlayerController->PlayerState);
    if (!ensure(PlayerStateWarlocks != nullptr)) return;
    PlayerStateWarlocks->SetPlayerName(PlayerName);
}

void UPlayerName::NativeConstruct()
{
    Super::NativeConstruct();

    if ( !Owner.IsValid() )
        return;
    
    APlayerState* PS = Owner->GetPlayerState<APlayerState>();
    APlayerStateWarlocks* PlayerState = Cast<APlayerStateWarlocks>(PS);
    if (PlayerState)
    {
        PlayerState->SetPlayerNameWidget(this);
    }
    
}

at the end of the day right... a player uses the command to change their name, the UI for all clients needs to update, my code doesnt do that haha but i dont know exactly how todo it

kindred widget
amber barn
#

if that makes sense

amber barn
kindred widget
#

What calls this? UPuzzleGameInstance::SetPlayerName

queen escarp
#

hm spawning actors from the "level bp" has to be casted to the server right ?

#

thats not automaticly ?

#

since its from the level

#

or u cant rpc from that side right :/

sinful tree
#

You can't really do this.

void UPlayerName::NativeConstruct()
{
    Super::NativeConstruct();

    if ( !Owner.IsValid() )
        return;
    
    APlayerState* PS = Owner->GetPlayerState<APlayerState>();
    APlayerStateWarlocks* PlayerState = Cast<APlayerStateWarlocks>(PS);
    if (PlayerState)
    {
        PlayerState->SetPlayerNameWidget(this);
    }
    
}```
The playerstate may not necessarily be valid at the time that the widget is constructed, and you don't want to get the owner of the widget as that will always be the local client's player controller.
amber barn
amber barn
kindred widget
#

Ah. That's why then. That code would only run on the client.

amber barn
#

if that makes sense

#

in my picture the viewport/editor is the listen server the small window is the client and i run the command on the editor

kindred widget
#

Ah. I missed the RPC.

#

Yeah. Server won't run OnReps automatically.

amber barn
#

i know what im doing isnt right i just wanna see if this will work cause i think it should?

im ignoring the race condition for now

sinful tree
#

Again, with the playerstate being valid at the time you're doing it of course 😛

kindred widget
#

You can call the OnRep directly on server, but it's not wise. And to fully answer the question I have to critique that the Playerstate should not know about the widget.

amber barn
#

yeah 100% agree the playerstate shouldnt know about the widget

#

im getting all mixed up with where i should do what

kindred widget
#

The Setting code, and the OnRep should both be calling a delegate broadcast. The widget should be bound to that.

amber barn
#

playerstate has the name

#

ah there it is, i dunno what a delegate broadcast is and how to bind a widget to it, lemme look it up

kindred widget
#

Check out DECLARE_DYNAMIC_MULTICAST_DELEGATE

amber barn
#

oh god this looks complicated, ill learn about it, ok thanks

sinful tree
#
// This gets declared just after your #includes in your .h
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnPlayerNameChangedDelegate);


//Later on in your class definition
public:
    UPROPERTY(BlueprintAssignable)
    FOnPlayerNameChangedDelegate OnPlayerNameChanged;


//.cpp
void APlayerStateWarlocks::OnRep_PlayerNameCustom()
{
    OnPlayerNameChanged.Broadcast();
}
#

As for binding in the widget... Umm.... That part I'm not great at. XD

#

At least not in C++.

amber barn
sinful tree
#

Sure

kindred widget
#

The binding you can just do in the widget's Construct.
PlayerState->OnPlayerNameChanged.AddUniqueDynamic(this, &ThisClass::MyFunctionIWantToCallWhenThisRuns);

queen escarp
#

hm spawning actors from the "level bp" has to be casted to the server right ?
thats not automaticly ?
since its from the level
or u cant rpc from that side right :/

#

its only visible on 1 client

kindred widget
#

RPCed. You can't cast to the server. Technically you cannot cast "to" anything.

queen escarp
#

ah you that what i ment

#

but then i should run it on the server or ?

upbeat basin
sinful tree
#

The level blueprint effectively runs on both the server and client independently.
The events that can be triggered within the level blueprint can also happen on both the client and server - for example, Begin Play will fire on both.

If you ensure whatever event that is driving the spawning is running on the server, by using something like a Has Authority check, then only the server should be running it.

You cannot send a Server RPC through the level blueprint. Server RPCs can only be sent on client owned actors, such as their controlled pawn, the player controller and playerstate.

queen escarp
#

yeah thats what i mean

#

like for now im running a tic for every 20 sec spawn an actor

#

but it only shows on 1 client

upbeat basin
#

As Datura suggested if you use HasAuthority check you should be able to make it spawned in Server so it can replicate to others

#

Do you have any checks or branches before the spawn node?

queen escarp
#

no

upbeat basin
#

Tick should also be running on both server and all clients, so it should actually spawn one on server, which should be replicated if the actor also is, and then on all clients locally

queen escarp
#

yeah thats why its strange

#

i mean this is how im spawning on the level Bp

#

this should be replicated right

upbeat basin
#

Well right now this should spawn the actor on server and on all clients. And if the actor is replicated, the one created in server should be replicated to all which would cause clients to have 2 actors

#

But it might also prevent the client ones from spawning since the collision override rule is set to not spawn and you're spawning them at the same location

agile loom
# queen escarp

Why are you not using the spawn zone actor for spawning them?
Also, you don't need to replicate the spawn zone actor, just use the Is Server node to make sure you are the server and then start the spawn

queen escarp
#

@agile loom whats that

#

@upbeat basin oh ok so what i should use has authority?

#

ok so im using a dedicated server tbh dose that matteR ?

agile loom
queen escarp
#

and now your in the "zone" actor bp right

#

not in level bp

agile loom
#

The zone actor is not replicated, but the actor that we spawn is replicated

queen escarp
#

@agile loom but why not in the level bp ?

#

whats the reson for not

kindred widget
#

Everything.

#

Generally speaking. Level blueprint is the very last place you ever want to do anything. There's almost always a better place for it.

#

In your case. Lets say you make a second level and want to spawn stuff in places. Wouldn't you rather just drop some new zones in and be done? Or would you rather have to open the level BP and recode all of this for a second time?

queen escarp
#

hm true

queen escarp
#

but then i have to rpc to server right

#

?

dark edge
queen escarp
#

you know what.. i missed a replicate the actor on the item itself-.-'

#

ok so another issue or rather tip im doing a kinda "duel arena" thingi so i need a win condition the first "player" to reach 20 kills the player kills is variable stored in the player BP but how would i set that up ? in the game mode or something ? how would i check each player who was the most etc ?

amber barn
#

hi guys, i have a delegate that is mostly working but its not calling the function i specified.

void APlayerStateWarlocks::OnRep_PlayerNameCustom()
{
    // console log player name
    UE_LOG(LogTemp, Warning, TEXT("Player name changed to %s"), *PlayerNameCustom);
    OnPlayerNameChanged.Broadcast();
}

i have confirmed this runs when i change the player name via a console command

but then

void UPlayerName::SetName()
{
    UE_LOG(LogTemp, Warning, TEXT("UPlayerName::SetName()"));

    // get player name from player state
    APlayerStateWarlocks* PlayerState = Cast<APlayerStateWarlocks>(GetOwningPlayerState());
    if ( !PlayerState ) {return;}
    FString PlayerName = PlayerState->GetPlayerNameCustomTwo();
    
    PlayerNameLabel->SetText(FText::FromString(PlayerName));
}

void UPlayerName::NativeConstruct()
{
    Super::NativeConstruct();
    
    APlayerStateWarlocks* PlayerState = Cast<APlayerStateWarlocks>(GetOwningPlayerState());
    if ( !PlayerState ) {return;}
    PlayerState->OnPlayerNameChanged.AddDynamic(this, &UPlayerName::SetName);

    UE_LOG(LogTemp, Warning, TEXT("UPlayerName::NativeConstruct()"));
}

SetName() is not running, i have confirmed NativeConstruct() is running at startup

the UPlayerName Is a widget above my characters head that displays their name

Datura and Authaer thanks for the help before!

lusty viper
#

I Have this logic for respawning my player character. Right now i try to make this suitable for multiplayer. My problem now is that it wont work on clients, it only does on the server. the server event runs on the server, and the other event is a multicast

#

what doesnt work now is that the rotation gets reseted to face always in the positive x direction for all clients.
here is the logic for that

#

Is the problem that the rotation of the spring arm (which are used for the calculation of the rotation) are not synced? or replicated? Setting the springarm to replicate didnt solve this tho.

kindred widget
# amber barn hi guys, i have a delegate that is mostly working but its not calling the functi...

Chances are likely that your OnRep is running before the widget's construct. Generally you will need to bind stuff and then call the same update function in a lot of multiplayer situations.

Also for your delegate. Two things. Use AddUniqueDynamic instead of AddDynamic. This ensures only one binding even if you remove and readd that widget for some reason. It'll ensure in editor at least if you try that. And a nice thing I prefer is using &ThisClass::SetName as I tend to copy bindings or move them around at times. This makes it easier just to know you're generically calling the function in this class and not have to always write out the class name.

amber barn
# kindred widget Chances are likely that your OnRep is running before the widget's construct. Gen...

awesome thanks for the tips

Chances are likely that your OnRep is running before the widget's construct. Generally you will need to bind stuff and then call the same update function in a lot of multiplayer situations.
I thought so as well but.. since its a command i can run anytime, it should be ok, see the log and the time between when the player name is set

void APlayerStateWarlocks::OnRep_PlayerNameCustom()
{
    // console log player name
    UE_LOG(LogTemp, Warning, TEXT("Player name changed to %s"), *PlayerNameCustom);
    OnPlayerNameChanged.Broadcast();
}

the on rep is running

kindred widget
#

Right. But breakpoint your OnRep and the Widget Construct. I'll bet your OnRep runs first.

#

Your Construct event just needs to call SetName after the delegate binding.

amber barn
kindred widget
#

Yeah

amber barn
#

hahah bro, what the heck

#

on play/spawn the name is set to my desktop.. no idea why im not calling that command, i call the command via the console to set player name to 123 and it doesnt call the delegate

#

haha

kindred widget
#

That's normal. That's Null OSS. If you use Steam or EoS, or any console OSS like Xbox or Sony, it'll set the name automatically to your Username there. Null randomizes a name like that.

#

How are you getting that though? Your code from above those get that name.

amber barn
#

im setting the 123 via a console command

#
void UPuzzleGameInstance::SetPlayerName(const FString& s)
{
    APlayerController* PlayerController = GetFirstLocalPlayerController();
    if (!ensure(PlayerController != nullptr)) return;
    PlayerController->PlayerState->SetPlayerName(s);

    // get the player state warlocks
    APlayerStateWarlocks* PlayerStateWarlocks = Cast<APlayerStateWarlocks>(PlayerController->PlayerState);
    if (!ensure(PlayerStateWarlocks != nullptr)) return;
    PlayerStateWarlocks->SetPlayerName(s);
}
kindred widget
#

Did you override that in your playerstate?

amber barn
# kindred widget Did you override that in your playerstate?

hmm not sure what you mean, this is the playerstate code

void APlayerStateWarlocks::SetPlayerName_Implementation(const FString& S)
{
    PlayerNameCustom = S;
}

bool APlayerStateWarlocks::SetPlayerName_Validate(const FString& S)
{
    return true;
}

void APlayerStateWarlocks::OnRep_PlayerNameCustom()
{
    // console log player name
    UE_LOG(LogTemp, Warning, TEXT("Player name changed to %s"), *PlayerNameCustom);
    OnPlayerNameChanged.Broadcast();
}

    UFUNCTION()
    void OnRep_IsReady();

    UPROPERTY(ReplicatedUsing = OnRep_PlayerNameCustom)
    FString PlayerNameCustom;

    UFUNCTION()
    void OnRep_PlayerNameCustom();

    UPROPERTY(BlueprintAssignable)
    FOnPlayerNameChangedDelegate OnPlayerNameChanged;
    
    UFUNCTION(BlueprintCallable, Category = "Gameplay")
    FString GetPlayerNameCustomTwo() const { return PlayerNameCustom; }
kindred widget
#

Okay. That explains how that's working. But your config function isn't running now?

amber barn
# kindred widget Okay. That explains how that's working. But your config function isn't running n...

yep so

{
    // console log player name
    UE_LOG(LogTemp, Warning, TEXT("Player name changed to %s"), *PlayerNameCustom);
    OnPlayerNameChanged.Broadcast();
}

this runs when i console command 'SetPlayerName 123'

but this doesnt

void UPlayerName::SetName()
{
    // if ( !Owner.IsValid() )
    //     return;

    // console log
    UE_LOG(LogTemp, Warning, TEXT("UPlayerName::SetName()"));

    // get player name from player state
    APlayerStateWarlocks* PlayerState = Cast<APlayerStateWarlocks>(GetOwningPlayerState());
    if ( !PlayerState ) {return;}
    FString PlayerName = PlayerState->GetPlayerNameCustomTwo();
    
    PlayerNameLabel->SetText(FText::FromString(PlayerName));
}

but SetName() must be running cause its changing my name to desktop etc right?

kindred widget
#

It's at least running once.

amber barn
#

yep

kindred widget
#

Ah.

#

Which machine are you running the exec on?

amber barn
#

the listen server / editor

#

wait wait

    UFUNCTION(Server, Reliable, WithValidation)
    virtual void SetPlayerName(const FString& S) override;

shouldnt this by client -> server?

kindred widget
#

It will run even on a server. It'd just run locally on a listenserver.

#

I'm not sure why your OnRep isn't running then. 😦

queen escarp
#

guys how would i track number of players in game ?

oak pond
#

well there’s literally a get current players node or something for the default subsystem

#

but idk if that works with everything

lusty viper
kindred widget
amber barn
kindred widget
#

Hope you get it. 😄 Is a weird bug. Probably just overlooking something.

amber barn
#

yeah 100% will see it tomorrow haha

kindred widget
lusty viper
#

The set control rotation is only available on the controller
I should probably move my rotation logic to the controller then right? or just set the control rotation inside the pawn via a getter of the controller?

oak pond
#

would it be a bad idea to have fast moving projectiles? I know projectile movement replicates, but I can imagine fast ones breaking a lot

#

and might not even need projectile movement component if they just travel in a straight line

#

so I’m wondering if there’s any kinda hitscan fakery for really fast projectiles that would work

quasi tide
kindred widget
#

IE, you can do a IsLocallyControlled check and if yes, GetController->SetControlRotation

blazing thicket
#

Hi guys! Can someone please give me some advice? I'm having trouble loading game saves when connecting to a dedicated server. My logic is as follows - clients select a character class, this class is saved using SaveGameToSlot then the client connects to the server and the selected character class is spawned on the map. The character spawn function is created in GameMode and is called using RPC on the controller, I also run LoadGameFromSlot on EventBeginPlay in the controller and get the saved character class which I then set for the spawn function. If I run the game in the engine everything works fine, but if I run the server and connect to it as a client then my character class variable is not passed to the spawn function. Any help would be appreciated. Here's a log of the spawn error on the server:
LogStreaming: Warning: LoadPackage: SkipPackage: /Game/AdvancedLocomotionV4/Blueprints/CharacterLogic/KokoTeam_Characters/ALS_ForestKid_Koko (0xBF1C553CD651EE0D) - The package to load does not exist on disk or in the loader
LogNetPackageMap: Warning: UPackageMapClient::InternalLoadObject: Unable to resolve default guid from client: ObjectName: /Game/AdvancedLocomotionV4/Blueprints/CharacterLogic/KokoTeam_Characters/ALS_ForestKid_Koko, ObjOuter: NULL
LogBlueprintUserMessages: [Combat_PlayerController_C_2147482465]
LogBlueprintUserMessages: [DCSGameMode_C_2147482489] Spawning:
LogScript: Warning: UGameplayStatics::BeginDeferredActorSpawnFromClass: can not spawn an actor from a NULL class

kindred widget
blazing thicket
kindred widget
#

I'm not sure. I'm not used to having that kind of issue with hard pointers to classes. :/

blazing thicket
kindred widget
#

Not sure. Your server seems to be the one with the problem. But does your client have access to the class? You don't have any checks to see if the class is valid before the RPC

blazing thicket
deep shore
lusty viper
kindred widget
#

I don't think he replied to the correct person.

deep shore
lusty viper
#

I tried it on all replication modes which did not do much of a difference. The Pawn just wont rotate

#

I solved it on a different way now, can someone rate this? I basically calculated the rotation beforehand, and then applied it on the multicast. This takes more bandwidth i assume, shouldnt matter tho if its only once every few seconds, right?

blazing thicket
kindred widget
outer sphinx
manic lichen
#

Hi does anyone have a good resource to learn about peer to peer in unreal?

hollow eagle
#

unreal does not support p2p without you writing your own custom netdriver (and no, there aren't really any resources on that)

prisma snow
#

the closest is listen server, which I'd normally recommend, although you still have to deal with NAT issues, relay servers, matchmaking server etc

pseudo crest
#

Hi, since yesterday my game is returning NetDriverListenFailure when I create a session only on shipping and only deployed on steam.

#

I've deployed a development version and it works fine.

#

I think it's happening on UWorld::Listen

#

Strangely yesterday steam updated Microsoft VC Redistribute when I opened the game on a version that were working fine.

#

I also rolled back the game to previous working versions and all of those are now showing the same behaviour

#

I will try disabling SteamSockets and shipping it to see if the pluguin is the problem. Anyone else is having this?

meager spade
#

hope not, or we will have angry players :p

pseudo crest
#

Sadly it must be only happening in my project

obsidian cargo
#

Are there mechanisms to replicate a variable only to a specific client? What about sending an RPC from server to a specific client?

#

I'm working on looting and XP, and need to send info just to specific clients. IE: How much XP the client has gained, dropping pickups that only they see, etc.

meager spade
#

i mean this would be a rpc

#

why would you use a replicated prop?

#

unless you maintained an array of the players and there stuff

obsidian cargo
#

Prop for persistent items on the ground. IE: Diablo style loot

#

XP is an ephemeral event that would make sense as RPC

meager spade
#

yes but you would send an rpc with the items to spawn

#

and client just spawns the stuff locally

#

or w/e

obsidian cargo
#

Ah, I was thinking a fast array of items with ID, position, etc, that the client can use to indicate when they pick them up

meager spade
#

or if they are replicated pickups, you could set owner to the person who needs them

#

then mark it OnlyOwnerSee

obsidian cargo
#

And then also having the item actors spawn locally

meager spade
#

🤷

obsidian cargo
meager spade
#

or you override

#

IsNetRelevantFor

#

and match the viewer to the target

obsidian cargo
#

I was thinking of IsNetRelevantFor

meager spade
#

(as long as your not using repgraph)

pseudo crest
#

I shipped the game without SteamSockets, it's working again.

meager spade
#

we use steam sockets just fine

obsidian cargo
#

Wait I haven't used RepGraph yet. I thought those were the same

#

With net relevance I could assign a "Loot Rep" actor to each player and send data that way?

pseudo crest
#

I don't know why them

#

I only use Sockets to get server latency for the server browser

icy jetty
#

So now what, no more ping column ?

meager spade
#
!NetDriverDefinitions=ClearArray
+NetDriverDefinitions=(DefName="GameNetDriver",DriverClassName="/Script/SteamSockets.SteamSocketsNetDriver",DriverClassNameFallback="/Script/SteamSockets.SteamNetSocketsNetDriver")

[/Script/SteamSockets.SteamSocketsNetDriver]
NetConnectionClassName=/Script/SteamSockets.SteamSocketsNetConnection
ConnectionTimeout=80.0
bNeverApplyNetworkEmulationSettings=true
InitialConnectTimeout=120.0
NetServerMaxTickRate=60
bClampListenServerTickRate=true
MaxNetTickRate=60
KeepAliveTime=0.2
MaxClientRate=120000
MaxInternetClientRate=120000
RelevantTimeout=5.0
SpawnPrioritySeconds=2.0
ServerTravelPause=4.0```
#
bEnabled=true
SteamDevAppId=XXXXX
bAllowP2PPacketRelay=true
P2PConnectionTimeout=90
P2PCleanupTimeout=1.5````
#

this our setup, and steam sockets works fine

#

obvs i marked out the app id

pseudo crest
#

Yeah, I forgot how to code block

#
!NetDriverDefinitions=ClearArray
!+NetDriverDefinitions=(DefName="GameNetDriver",DriverClassName="OnlineSubsystemSteam.SteamNetDriver",DriverClassNameFallback="OnlineSubsystemUtils.IpNetDriver")
+NetDriverDefinitions=(DefName="GameNetDriver",DriverClassName="/Script/SteamSockets.SteamSocketsNetDriver",DriverClassNameFallback="/Script/SteamSockets.SteamNetSocketsNetDriver")

[OnlineSubsystem]
DefaultPlatformService=Steam
bHasVoiceEnabled=true
PollingIntervalInMs=20

[OnlineSubsystemSteam]
bEnabled=true
SteamDevAppId=XXXXXX
SteamAppId=XXXXXX
GameServerQueryPort=27015
bVACEnabled=1
P2PConnectionTimeout=90
bInitServerOnClient=false

[/Script/OnlineSubsystemSteam.SteamNetDriver]
NetConnectionClassName=OnlineSubsystemSteam.SteamNetConnection

[Voice]
bEnabled=true

[Core.Log]
LogOnline=All
LogOnlineGame=All```
#

This is mine defaultengine.ini

meager spade
#

thats wrong thouhg

#

just replace your stuff with mine

#

set the appid, and try it

pseudo crest
#

You don't know how stupid I feel right now

meager spade
#

you running dedicated servers?

pseudo crest
#

p2p

meager spade
#

right so why do you have bInitServerOnClient set to false?

pseudo crest
#

Oh

meager spade
#

just try my code

#

you can always revert back

#

but see if it works for you

pseudo crest
#

I will try right now, thanks.

icy jetty
#

And now Kaos owns 20% of your revenue 😀

visual glen
#

hey all, so I have been messing around with my first project, noticing that my UI gets added more then once. I'm doing something pretty simple with it if anyone has tips for this please feel free to let me know

Code example:
` if (ScoreUIWidget != nullptr)
{
ScoreUI = CreateWidget<UScoreUI>(GetWorld(), ScoreUIWidget);

    if (ScoreUI != nullptr)
    {
        ScoreUI->AddToViewport();
    }
}`
blazing thicket
prisma snow
#

Question for multiplayer people: one of my colleagues has been trying to integrate Valve's sockets into Unreal, it's working (for example, a replicated object moves on both client and server). However, there's an error that is hard to solve/figure out, related to UConnection.cpp, lines from 4594:

// Detach old player if it's in the same level.
    check(LocalPlayer);
    if( LocalPlayer->PlayerController && LocalPlayer->PlayerController->GetLevel() == PC->GetLevel())
    {
        if (LocalPlayer->PlayerController->GetLocalRole() == ROLE_Authority)
        {
            // local placeholder PC while waiting for connection to be established
            LocalPlayer->PlayerController->GetWorld()->DestroyActor(LocalPlayer->PlayerController);
        }
        else
        {
            // tell the server the swap is complete
            // we cannot use a replicated function here because the server has already transferred ownership and will reject it
            // so use a control channel message
            int32 Index = INDEX_NONE;
            FNetControlMessage<NMT_PCSwap>::Send(this, Index); //this gets triggered and causes the error
        }
        LocalPlayer->PlayerController->Player = NULL;
        LocalPlayer->PlayerController->NetConnection = NULL;
        LocalPlayer->PlayerController = NULL;
    }

The logs print an error message: recieved invalid swap message with child index -1, which is likely caused by the fact that the previous code is triggered.
It seems something related to the custom socket implementation that is missing, but we cannot find a cause or solution

visual glen
#

is it best practice to add any UI only on the server?

prisma snow
pseudo crest
#

Doesn't UI only have reference on clients?

prisma snow
#

It's a client-side thing, ideally detachhed as much as possible from gameplay logic

dark edge
#

That's like.... The opposite

visual glen
#

glad I got a response 😆 ty

dark edge
#

Do you mean "show certain UI only on LISTEN server"?

visual glen
#

my original post was talking about how I seem to be getting more than one UI being added to the viewport, trying to figure out how to get that down to one

dark edge
#

That's a widget

dark edge
terse talon
visual glen
#

potentially per client, the code is being called on BeginPlay on my Character class

terse talon
pseudo crest
meager spade
#

might have to turn logs on

#

but it works fine for us, so not sure what your issue is :/

visual glen
terse talon
pseudo crest
#

Wait, should I remove this too from the engine.ini?

DefaultPlatformService=Steam
bHasVoiceEnabled=true
PollingIntervalInMs=20```
kindred widget
visual glen
terse talon
visual glen
#

oh thanks, that's actually huge

#

I'm assuming that I can attach that to the HUD Class in my custom GameModeBase

#

I needed this lol TY all that contributed

lost inlet
quasi tide
#

AHUD just serves as a widget holder.

#

And the PC is just telling it to show/hide or w/e.

#

It's like extra indirection for the sake of indirection

kindred widget
#

I don't like putting things in the Controller. It has enough work as a networking hub and a control delegator. And you can very easily make a precasted static to get your HUD.

prisma snow
#

although I still end up using PC as the dump of every general functionality sometimes

quasi tide
#

Pretty much most communication to the player ends up going through the PC (at least not like...character related stuff)

#

Like "PC - show this widget"

#

Or w/e

icy jetty
#

Well if you want to get HUD you need to get PC anyway iirc

quasi tide
#

So, for me, it's not a matter of accessing the HUD itself - it's just a lot of things end up going through the PC anyway (rpc wise)

visual glen
#

I just made a new GitHub branch for this. I did a lot of workarounds and learning to try to get the UI to sync up between clients

kindred widget
#

I'm working on a project right now that has a 20k line PlayerController.cpp file. 2600 line .h file. And that's only one part of it's C++ hierarchy And the BP for it is stupidly massive. I really do not like anything more in the PC than there needs to be. 😂

visual glen
#

but if I can make it more simple to have just 1 version of the UI for the rest of the development - that'd be ideal

icy jetty
rocky kestrel
#

What could be reason shipping dedicated server doesn't work? And how to use -log on on that? Development server works 100% and I can play it others can play it.

quasi tide
prisma snow
kindred widget
quasi tide
#

🤔

prisma snow
#

Ye I just playtest

quasi tide
#

Oh - so Max > Duro confirmed?

prisma snow
#

^^

quasi tide
#

Time to make a PC-like actor, specifically for client-specific RPC calls.

quasi tide
prisma snow
#

also now that I have your attention just in case

quasi tide
#

Oh gee - look at the time...

kindred widget
#

😄 Nah. Duro's cool. I did take your advice on interaction components.

icy jetty
prisma snow
quasi tide
#

The good news is that if you removed it, you wouldn't get the error anymore.

#

INDEX_NONE is -1 by default I believe.

#

Don't know what that line is even doing and I'm not at my computer that has UE, so I can't dig either

limpid parcel
#

ui will forever be my opp

radiant dew
#

i want to give everyone the same view as soon as this level starts but this does not work... Using the get player controller i can only reference 1 player, How should i go about referencing all players who start this level

kindred widget
radiant dew
kindred widget
#

Yeah. Sec. There's a setting somewhere that will help if memory serves.

kindred widget
dark edge
kindred widget
#

Don't ask me. 😄 You want to see my personal project's PlayerController.cpp?

AShooterSurvivalPlayerController::AShooterSurvivalPlayerController()
{
    PrimaryActorTick.bCanEverTick = true;
}

void AShooterSurvivalPlayerController::BeginPlay()
{
    Super::BeginPlay();

    if (IsLocalController())
    {
        if (UCommonUIActionRouterBase* CommonActionRouter = GetLocalPlayer()->GetSubsystem<UCommonUIActionRouterBase>())
        {
            CommonActionRouter->OnActiveInputModeChanged().AddUObject(this, &ThisClass::HandleCommonInputModeChanged);
        }
    }
}

void AShooterSurvivalPlayerController::HandleCommonInputModeChanged(ECommonInputMode NewInputMode)
{
    if (NewInputMode == ECommonInputMode::Menu)
    {
        FlushPressedKeys();
    }
}```
#

This is how much I adore using my playercontroller.

#

I don't remember off hand. But I don't think the BP for this even has anything in it.

quasi tide
#

How do you handle say, opening the inventory? @kindred widget

#

(Assuming it's not character specific obviously)

#

Or say, you interact with a keypad and the server has to tell the client to show the keypad UI for example

kindred widget
#

Inventory is an easy one. I have a player specific interaction component on my player pawn that does a few hotkeys. Really need to set up some real inputs sometime though. 😄

#

Don't even care about HUD there. Interaction straight to widget.

quasi tide
#

Yeah - I realized the inventory probably wasn't the right UI thing to pick 😅

visual glen
#

my code is nightmare fuel to most - I add the UI and update the UI in the Character class. With the support of the GameStateBase

quasi tide
#

Well - it depends™️

visual glen
#

after earlier convo I am reevaluating it all

quasi tide
#

Like - updating the UI when you shoot your gun for example, I can understand why you might tie that into say the player class

#

(Not saying that's how you should mind you)

quasi tide
kindred widget
#

Local interaction is done. I use it currently for opening inventory screens to other items. Server interaction I'm still working on. I have two interaction components. One is on my player, that does the actual interaction. Since it also has access to ServerRPC from the owned player. The other is a component with a softpointer to a DA that I put on interactable stuff. It stores whether I need to RPC or can interact locally. I get entirely around dealing with interfaces doing this.

kindred widget
#

Er. Sorry. Brain failed. You have to hardcode it because they DIDN'T use a developer setting. It's just a config in a UGameInstanceSubsystem

dark edge
#

spaghet?

kindred widget
#

I know a good small part of it is UI handling. Only reason I've personally been in there. Just a lot of stuff.

limpid parcel
#

Me after struggling to make a simple health bar in multiplayer

quasi tide
#

Inbefore: "Instanced UObject"

kindred widget
quasi tide
#

So what flips that bool?

#

Say you have two things, one requires an RPC and one doesn't.

#

What flips it?

kindred widget
#

It's set on the instance.

quasi tide
#

The interactable instance?

#

Or you place it on the interactable's component. Then when you go to interact, you grab that component and then check it

kindred widget
#

For instance an actor I want to interact with to show an inventory. I don't want to RPC, it's false. I'd set it to true for a lightswitch. Actor class handles the interaction through Started, ongoing and completed delegates from the component.

quasi tide
#

Right, so my latter.

#

So your system is as follows:

  1. Component on anything that is interactable. It is here that you set if it can be local or not.
  2. When something interacts with something else, locally, you check if it can be done locally or not and if local, proceed, if not, route ServerRPC through the interacting actor
kindred widget
#

Yep

#

I find this approach nice so far. And I'm hoping it'll be easy to integrate with AI. As they can bind the delegate callbacks for completed and such as well in their AI tasks.

quasi tide
#

And the DA contains the widget class for the given UI. So nothing really holds references to UI itself.

#

Are you a fan of creating/destroying widgets when they're no longer needed? Or you a show/hide kind of programmer?

kindred widget
#

Yeah. Or it will. Still working on that one. Been debating if I want to go with a listed view of fragmented widgets that hold specific like data, or a single more specialized one per actor type.

#

Somewhere in the middle. Pool when it's worth it. Actually CommonUI's Stack does this for you. 😄 And I've started using Listviews and Tile.. whatever they're called a lot more due to just being able to throw an array of objects at them.

quasi tide
#

I've been seeing people talk more about fragments lately. Should probably look at Lyra to see what's up

kindred widget
#

They're just smaller data assets meant for a specific small subset of data. Like in my case, instead of having one tooltip widget with it all set up to display for one actor. I could use like a health display fragment that has a specific small widget for displaying health. Another one that has a small widget for displaying maybe durability. Another one that houses a name/description/icon. And then I could just iterate over these DAs, create their widgets, populate them from their data, and put them together in a VBox dynamically.

visual glen
#

which class is best to update/initialize UI within the HUD class?

kindred widget
#

You can initialize most of it on Beginplay.

visual glen
kindred widget
#

You create a child of AHUD?

visual glen
#

ya

kindred widget
#

It should be there as a greyed out node. Alternatively right click the Graph and just start typing it.

visual glen
#

doing it in C++ but ok I see the override works - thanks!

kindred widget
#

Don't forget the Super call.

visual glen
#

perfect got the first part working - thanks!

vital pecan
#

Can anyone suggest a good pattern for handling UI updates in response to updating an array on the server? For example, if I start a quest and add it to a TArray of active quests on the server, which is replicated to the client. I could use the OnRep of the array to broadcast a multicast delegate for anything that was interested in the update (aka a quest log UI widget), but it wouldn't be able to have info on which element in the array is new/updated. If I call a client RPC I can easily pass the info on what changed down to the client and include that in the broadcast, but the underlying TArray may not have replicated yet at that point, right?

#

I can think of plenty of non-performant ways of handling it, I was just hoping there was a more elegant solution I'm missing

kindred widget
vital pecan
#

Got it, thanks, looking into that now!

chrome bay
#
void OnRep_TheArray(const TArray<FWhat>& PreviousValue)```
vital pecan
#

Yup, that was on my mental list of 'doesn't feel quite right' solutions, thanks 🙂

#

An acceptable middle ground for the case of a small array, and then use FastArray for the bigger/more important cases

chrome bay
#

I'd say it's fine honestly. You can set a flag per-element when it's serialized client-side if you just want to skip through quickly

#

Honestly though, probably easier to just tell the UI "the array changed" and let it handle any rebuilding etc.

#

TArray still has some replication advantages over Fast Array, but FA does have nice QOL stuff

pale edge
#

I have a question, im pretty new to UE5 replication, but i've got an object that gets instantiated by the player on begin play. That actor is set to replicate, but my problem is it seems to be making duplicates of the object on the client side no matter what i do. Any thoughts?

vital pecan
#

Aye, it just hurt me a little inside to rebuild the whole UI component based on a change instead of just the piece I needed, if I could help it

chrome bay
#

yeah that's fair. An easier way to do quick comparisons, would be an incrementing counter

#

Depends how expensive the comparison actually is ofc

#

Hard to beat a straight up memcmp

vital pecan
pale edge
#

I think thats whats happening, yeah

chrome bay
#
  • you get the bonus one on clients when the servers' version replicates
#

Make sure you guard the code spawning the actor behind HasAuthority() or some suitable check, and make sure clients don't have authority on the spawning actor too (e.g, it's not a non-replicated actor itself)

pale edge
#

follow up question, the player needs to store a reference to the object that it creates, so will this reference be properly set in the case of a client that doesn't have authority?

#

i guess, should the variable be replicated?

#

oh huh, nevermind just tested it out and it seems to be working properly now

#

tysm!

#

actually now there are different problems but i'll give it a good shot at solving those before i post here more

chrome bay
#

Note the actor actor may replicate before the reference is updated however

#

The reference will eventually update, but just note that because the two actors replicate independently, you can't garauntee which will replicate first

pale edge
#

Ive stopped work for the day, but I was encountering an issue that may be similar to this, the instantiated object for player 2 on the server wasn't replicating movement even though it is set to do so. I think it's because the reference isn't set properly, but I'm unsure why it would do this since it's just make player->create object and assign it to a variable as a reference, which is replicated

#

And it moves on the client side, but yeah, not the server side

chrome bay
#

Yeah none of that should interfere with movement

#

If it moves client-side, it's because the client is moving it locally most likely

pale edge
#

Yup that's the case

chrome bay
#

The Server should be the one moving it, and all clients will receive that

pale edge
#

Then I think I understand how to fix it, this is really a server authoritative architecture huh? Thanks again, hopefully I can get it working tomorrow

chrome bay
#

Yeah. Ultimately you can do whatever you want to your local instance, the client could even choose to ignore what the Server tells it to do - but ultimately if a client wants to mess with something it's not authoritative over, it must ask the server to do it

#

And the Server checks the request and applies accordingly

#

(you can skip the checking part just to get it working, but that's where the security stuff comes in etc.)

pale edge
#

Yeah there's so much with networking that I've not even touched, even when I was doing my own stuff or working in unity, being an indie makes thinking about everything overwhelming at times but I'm sure it'll become easier as time goes on

pseudo crest
#
[2023.05.25-03.24.19:978][523]LogNet: ReplicationDriverClass is null! Not using ReplicationDriver.
[2023.05.25-03.24.19:978][523]LogNetCore: DDoS detection status: detection enabled: 0 analytics enabled: 0
[2023.05.25-03.24.19:979][523]LogSockets: Warning: SteamSockets: Cannot get information on an invalid socket handle, returning null
[2023.05.25-03.24.19:979][523]LogNet: Warning: Could not create socket for bind address 76561197992543984, got error SteamSockets: setsockopt SO_BROADCAST failed (0)
[2023.05.25-03.24.19:979][523]LogSockets: Warning: SteamSockets: Cannot get information on an invalid socket handle, returning null
[2023.05.25-03.24.19:979][523]LogNet: Warning: Could not create socket for bind address ::, got error SteamSockets: setsockopt SO_BROADCAST failed (0)
[2023.05.25-03.24.19:979][523]LogNet: Warning: Encountered an error while creating sockets for the bind addresses. 
[2023.05.25-03.24.19:979][523]LogNet: Error: InitBindSockets failed: 
[2023.05.25-03.24.19:979][523]LogNet: Warning: Failed to init net driver ListenURL: /Game/OnlineSystem/Lobby/Maps/Lobby?listen: 
[2023.05.25-03.24.19:979][523]LogNet: Error: UEngine::BroadcastNetworkFailure: FailureType = NetDriverListenFailure, ErrorString = , Driver = GameNetDriver IpNetDriver_2147482417
[2023.05.25-03.24.19:979][523]LogNet: Warning: Network Failure: GameNetDriver[NetDriverListenFailure]: 
[2023.05.25-03.24.19:979][523]LogNet: NetworkFailure: NetDriverListenFailure, Error: ''```
#

I think I found the error from the log

pseudo crest
#

I compared with the Stand Alone log and I think I located the problem: Unable to load SocketSubsystem module STEAM

amber barn
#

hello hello, me again with the same problem and some progress

command/exec function to set playername called by the player at runtime via console

void UPuzzleGameInstance::SetPlayerName(const FString& s)
{
    APlayerController* PlayerController = GetFirstLocalPlayerController();
    if (!ensure(PlayerController != nullptr)) return;
    
    AGameModeBase* GameModeBase = GetWorld()->GetAuthGameMode();
    if (!ensure(GameModeBase != nullptr)) return;
    GameModeBase->ChangeName(PlayerController, s, true);
}

onrep playername change in player state

void APlayerStateWarlocks::OnRep_PlayerName()
{
    Super::OnRep_PlayerName();

    OnPlayerNameChanged.Broadcast();
}

player name widget binding

void UPlayerName::NativeConstruct()
{
    Super::NativeConstruct();

    APlayerStateWarlocks* PlayerState = Cast<APlayerStateWarlocks>(GetOwningPlayerState());
    if ( !PlayerState ) {return;}
    PlayerState->OnPlayerNameChanged.AddUniqueDynamic(this, &ThisClass::SetName);
}

void UPlayerName::SetName()
{
    APlayerStateWarlocks* PlayerState = Cast<APlayerStateWarlocks>(GetOwningPlayerState());
    if ( !PlayerState ) {return;}
    
    FString PlayerName = PlayerState->GetPlayerName();
    PlayerNameLabel->SetText(FText::FromString(PlayerName));

    UE_LOG(LogTemp, Warning, TEXT("Player name is %s"), *PlayerName);
}

problem in picture, i run the command on the listen server and both actors get their name updated to same thing .. but on the client no change is detected

sinful tree
amber barn
#

i think we spoke about this last time and you can't replicate it i think

sinful tree
#

Ok, so Game Instance is not a replicated actor. Game Mode only ever exists on the server. You're not RPCing anything.

amber barn
#

mm ok gameinstance != gamemode

but is game instance server only? or for each client?

#

each client right

sinful tree
#

Game Instance is a unique actor for each "instance" of the game running. When you start the game up, Game Instance is loaded.

amber barn
#

mmm makes sense ok, so sorta of client only

sinful tree
#

No

pseudo crest
#

GameInstance is literally the game's instance. Only your pc can access it.

sinful tree
#

Cuz it also exists on clients.

#

err server XD

amber barn
#

ahh yep sorry

#

get that

sinful tree
#

So you must send the RPC through an actor that is client owned, like the playerstate, playercontroller, etc... Once running on the server, then you can access GameMode.

pseudo crest
#

GameMode is for server only things, like validade if a player died or spawn things

amber barn
#

oh godddd haha i understand what youre saying ok let me try something

pseudo crest
#

I advise you to check the epic documentation about the hierarchy

amber barn
#

ughhh

    APlayerStateWarlocks* PlayerState = Cast<APlayerStateWarlocks>(PlayerController->PlayerState);
    if (!ensure(PlayerState != nullptr)) return;
    PlayerState->SetPlayerName(s);

then what?

amber barn
pseudo crest
#

I think the Player's name can be accessed in the PlayerState easly

icy jetty
#

You prly know about it tho

sinful tree
#

Your SetPlayerName() on playerstate then can call the GameMode function to set the name.

amber barn
#

in the onrep in player state? i call gamemode change name>

sinful tree
#

If you're trying to use the Game Mode's ChangeName() function then you'd have whatever RPC call that function.

amber barn
#

RPC != onrep
right?

#

theyre two different things?

sinful tree
#

OnRep == The variable change was received on clients.