#multiplayer
1 messages · Page 253 of 1
Why does change weapon do the work and not the notify?
good question...
does the notify have to?
I would prefer the notify did that work yeah
ur saying just set the equipped on the buytton clicked?
how would it set the old one hidden, and the new one visible?
You still need an rpc to get it to the server
All are hidden but the new one
It is included in the all weapons
In c++ you can get the previous value of a replicated variable, but I don't think you can do it in BP
like on equip change notify i can set the new one visible
but not the old one hidden
if u get me
so should i set it hidden on the server + multicast then visible on rep?
Set them all hidden if they aren't the new one
loop through hotbar and set hidden on every equip chjange?
I would do all of the logic in the onrep
its only 5 items so it shouldnt be that consuming
and a server rpc to call the set equip so it runs on server?
It wouldn't be consuming if it was 500
okay
Yes, that's the simplest and most robust way to do most things.
ill lyk!
im getting an issue where after switching it shows nothing
unless i switch to a diff slot and back to that one then it shows agian
after switching from what to what
is there any error?
Your HotBar may not have the equipped weapon at the time the OnRep of equipped weapon is firing.
Try just hide all hotbar entries that aren't CurrentWeap then just show CurrentWeap
don't depend on it being in AllWeaps
looping through all hotbar, if its not equipped, hide it
Also... Doesn't hiding an actor end up causing it to not be replicated?
got it
Don't know a thing about that, maybe want to do hidden in game or some other "still there but not visible" state
show current code
oops
i forgot the equipped weapon variable connected to visibility
it still doesnt work ^
i changed it
i forgot to drag the equipped weapon
pretend its there
same issue
Ok... So, it doesn't stop replication when hidden... HOWEVER... Setting hidden on the server ends up setting it hidden for everyone.
Always or with Replicate Movement?
I have replicate movement off.
I really wish there was a writup somewhere with what all did what and what is guaranteed to replicate before what else
Like can a replicated pointer beat the thing it's pointing at to the client?
so i need to set it hidden on the server?
what am i doing wrong..
You already are doing so by using the OnRep.
And you dont want the server setting anything hidden as it'll end up hiding that actor for everyone.
but im setting it hidden on the server
then visible on the server
whats the issue i dont undertstand
In this case they do
Errr yea right XD
depending on what hidden actually means
The loop probably should only happen on the server in that case, there's no real reason to have all clients do that loop.
Try this.
OnRep -> Sequence -> has authority? -> yes -> do all the hiding and unhiding
-> is locally controlled? -> yes -> attach to 1pp
-> no -> attach to 3pp
try that yeah
kk
being hidden is evidently replicated
I'd split the problem up, just have all weapon actors attached to capsule out floating in space and make sure the hide / unhide works, then worry about attaching to meshes
so this is working for the third person mesh but not the first person
code:
two part
same func
Attachment is also replicated.
If you're using the gun actor for any kind of logic then it would need to be in the appropriate place on the server.
That's a part of Replicate Movement right?
god damnit
How would you have a split attachment then? 1 replicated actor attached to different things on different machines
i should have replicate movement off?
i thought i should be replicating the movement
so the server hides it... the server shows it... then the client attaches it 1p or 3p, whats wrong with this method?
i have my base weapon class on replicates & replicates movement
what movement would you want to be replicating anyway?
on the 3rd pesron mesh
you'd replicate the fact that you fired or whatever
You'd replicate the fact that you played RifleFireRecoil, not the fact that the rifle moved smoothly over time as the animation played
okay i disabled replicate movements
so how come it works the second time i press the slot just not the first time?
show what pressing the slot does
and your current onrep code if it has changed since last time
full code from input event to the last thing
idk if that's your problem but that is a problem
also why do you even have Current Weapon Int as a variable
lose it
animation should be included on the weapon definition
What's this about, what is WeaponAdded? You're not using it in the onrep
btw that can screw up, you're not guaranteed to get every weapon added
just onrep Hotbar
when Hotbar changes, go remake the hotbar UI
i use onrep weapon added to add the image
OnRep_Hotbar -> rebuild UI
OnRep_CurrentWeapon -> show/hide and attach stuff
to the hotbar
if you call it fast enough it'll miss some
you aren't guaranteed to get every update
you are just guaranteed to have the final value
but this wouldnt cause the current issue right?
onrep my hotbar array ur saying
ah
no but I'd fix it now rather than trying to chase down a super bad bug
Yes you have 2 bits of state in your character.
What weapons are on hotbar, and what weapon is currently held.
when the hotbar changes, you wanna update the UI
when the held weapon changes, you wanna show/hide stuff and do attachment
when thing changes = OnRep, basically
so for the hotbar onrep
how would i know if a value has been added or removed from the array
who cares, just nuke and remake for now
thats what im saying, to make it
just empty the bar and refill it from Hotbar array
if you had like 1000 it'd be different
how do you do a for loop in blueprints
from 0 -> var
ig ic an just google it rq
nvm its pretty self explanatory
is this good?
anyways regardless if this works, we have a bigger issue on hand
i still dont understand why this logic doesnt work
lol
wtff
why is it doing that lol
its spawning in a big ass gun not putting it on the slot
why is it doing that lol
no
look at last screenshot
I don't like the raw for loop, you could just make a function on HotbarHUD that gets passed an array of weapon actors and does its thing
then it could just be HotbarHUD.Update(weaponactorarray)
does its thing
u mean sets them all blank?
but technically this should work
not sure why its not working
does all of the work
the character can just say "here's my weapon array, go nuts"
ill change it but why doesnt this work?
its literally spawning in a weapon into the game as a huge ass weapon
show the bit of code where you spawn the weapon
the computer is doing exactly waht you tell it to do
ye
why did it move to scale
i had it on location
wtf
its not longer attaching
so after deleting the weapon to add var it now no longer attaches and my hotbar stuff is not adding anymore
are you intending to no longer add a picked up weapon to your hotbar?
what happens after spawn weapon
looks like nothing
still same issue where its not showing on first person mesh
unless i switch weapons a couple times
Time to put breakpoints and see where it's failing
question about net dormancy
- I have an actor with a replicated bool (default true)
- I set this actor to be net dormant to start
- Game starts, but my player is not in net relevancy range of this actor
- Suddenly, the server toggles the bool to false. But there's no player in net relevancy range
- The actor goes dormant again
- When I move my player in net relevancy range, will I have stale data on the client until the actor wakes up?
Depends on a few things
Also your sequence of events doesnt make sense.
The actor goes dormant again
How does it go dormant again if:
I set this actor to be net dormant to start
It was already dormant?
Did you flush its dormancy when changing the bool?
Did you call ForceNetUpdate?
Things like this can cause different behavior.
So its important to be very specific.
If the Actor was Dormant to start with and it never changed dormancy while its bool value was changed.
It will send the last value it had prior to being dormant.
Which by your account is the default value.
UNetDriver::ServerReplicateActors_PrioritizeActors manages all of this
// Skip Actor if dormant
if ( IsActorDormant( ActorInfo, WeakConnection ) )
{
continue;
}
If an Actor is outright dormant, it will not be added to the consider list.
Meaning, it wont replicate any changes.
yeah forgot to mention, when the server toggles the bool to false, it also calls ForceNetUpdate
In that case it will have flushed its dormancy to ensure that value is up to date.
@chrome bay Is this a way to handle it instead?
I made the Sit action on the character, kind of feels right to have it there, as it's a player action like "Jump" or "Sprint" that has to do with the character doing something.
These are my dormancy settings and how I am replicating the chair to basically replicate a set boolean IsOccupied so that way no one else can sit on an occupied seat. I flush Net Dormancy right before replicating the Bool to set it to Awake just to replicate that change and off it goes back to Dormant All
That way we only replicate this Chair once. technically speaking.
The Sit function has all the necessary logic to handle moving the player onto the chair, disabling movement, and then calling SetSeatOccupied on the chair itself to state that the seat is taken. So I still need to replicate the chair for this one bool check. But at least I am just simply flushing to get out that new bool value, and instantly going back to dormant again anyhow.
I do the IsOccupied to turn off the 3D Widget that displays "Press E to sit" sort of thing. So I need that there. Otherwise I wouldn't need to replicate at all.
Just wanting your thoughts if that's the right setup.
And just wanting to confirm this is correct yeah?
https://gyazo.com/079d8794ebcd3ceceda901a9e59e855d
Everytime I sit on the chair and get off of the chair, the chair goes awake to replicate the bool above and goes back to dormant right after the update through using the Flush Net Dormancy, but the Server never changes? I thought that was a bit weird as I'd think it would change for all. But I guess it only matters for the clients because server always knows everything always right?
When you're testing in editor and you press f8 to stop possessing the character so you can float out and look at variables, when it's 2 players (listen server and client), you see what the first client see's/knows about on the content outline. Is there a way to switch that over to the listen server or another client so you can check what they see/know without it being a bunch of print strings?
hmmm if i have a few hundred actors that only need their initial data replicated, and never have RPC's or anything after spawn, would it be worth it to make a custom net channel to pipe them all through?
Oh I totally didn't see the push model bit!
Hello 🙂
I'm trying to have a different directional light between each client. I managed to do this with the "has authority" for a different directional light between the server and the client, but as long as there are multiple clients, they all have the same directional light.
I manage the directional light in the level blueprint (because I don't think you can reference it otherwise), and I have the impression that in the level blueprint, there's always some kind of replication for all clients.
I have an interface that appears in the level blueprint when I overlap a collision box in another BP.
Does anyone have any ideas for how to have these directional lights different between each client?
hello,
I have a hotbar system which spawns in all of the weapons that are in it, and only sets the equipped weapon visible when holding. i am having an issue where when changing weapons its not showing the weapon on the first person mesh (unless i change slots a couple more times) im thinking there might be a delay issue... or is this the proper way to hide and show actors on the server? please let me know thanks! (ignore the mess on the attachments, they are correct.)
questions, is the server supposed to hide weapons? am i hiding the weapon the proper way?
my layout
server-> hides weapon -> shows weapon
local client -> attaches weapon to arms
other client -> attaches to mesh
@digital herald
I am currently looking into your blaster game code to learn how the AO:yay/pitch is calculated, i can see the APawn::BaseAimRotation(); is not used and all the bool states are updating on anim tick, is it a good practice or will it be updated?
It's pretty typical for the anim instance to update its state in Tick, though an even more modern approach would be to update these variables using the Threadsafe update to take advantage of multithreading. I don't do this in this course, but I do show it in newer courses.
The Animation Blueprint has a Blueprint Threadsafe Update animation function, and in C++ it's done using a type called an Anim Instance Proxy. It's not too difficult to implement it in C++ but the process is slightly different.
I'm working on newer multiplayer content that takes advantage of the Anim Instance Proxy to update these in C++ using multithreading
this is how i use GetBaseAimRotation and its working not correctly, the local offset and server offset are not same.
I would use your approach i think
void UArmaAnimationInstanceBase::NativeUpdateAnimation(float DeltaSeconds)
{
Super::NativeUpdateAnimation(DeltaSeconds);
Speed = Character->GetVelocity().Length();
Direction = Character->GetCalculateDirection();
FRotator DeltaRotator;
if (Character->IsLocallyControlled())
{
DeltaRotator = (Character->GetBaseAimRotation() - Character->GetActorRotation()).GetNormalized();
}
else
{
DeltaRotator = (Character->GetControlRotation() - Character->GetActorRotation()).GetNormalized();
}
Pitch = DeltaRotator.Pitch;
Yaw = DeltaRotator.Yaw;
UpdateAnimPropertiesBP(); //use for IK Update in blueprints
}
I am updating those bools on notifies, like when crouch get animinstance and update that variable too
It's typically not recommended to change state on the anim instance from outside of it, rather, you should reach out from the anim instance and retrieve variables from elsewhere (character, etc) and have the anim instance update itself.
yeah but updating those on every tick in a mp game can cost lots of money 😄 ?
if i have like like 200 players connected and each of them is getting that update on every tick
Updating those variables isn't really enough to affect performance. If it gets to the point where it starts to do so, you can take advantage of the multithreaded method I mentioned above.
Ok and Thanks for that open source project, it has lots of usefull things 😄
No problem, and on the subject of Tick, think of your Anim Instance as holding states that can frequently change - if you are implementing event-based mechanics, such as one-offs like attacks, weapon firing, etc, then you're probably going to just play an Anim Montage rather than transition into a state machine's state, or in projects using motion matching, an anim in the pose database etc.
bump 🙏
not sure why its not showing on first person but it is for everyone else
does this set it visible on all clients too?
you are doing it on server, if the actor is replicated it will hide every where
but test it to make sure because sometimes things works not the expected way in unreal engine
Yes the actor is replicated, yes it hides on all clients (since its happening on the server) i am setting it visible on the server as you can see, but it is only showing as visible on the third person mesh. not the first person arms
as you can see here.
the first time i change to that slot it is invisible in my arms. if switch slots a few times then it is visible. could this be a delay issue? i am not sure why it's not working on the first switch
you are in FPP mode locally, so you need to attach the weapon locally to the fpp mesh
your state for other clients you are already tpp and should always be tpp, only switch the state locally
means visibility switch only locally
i dont change my state for others
i dont understand what ur saying
my mesh has a body component and arms
i attach the weapon to the arms locally and the mesh for everyone else
if you switch state of a replicated actor using server, it will change everywhere
yes
i understand that
i am hiding / showing the weapon via the server
and i am attaching via the clients
which is why i have a islocally controlled check
try clientrpc and call it by server which should do it correctly and you will no need for islocallycontrolled
for the attachment?
attachment and visibility
you only need server visibily if you want to replicate changes to other clients
yes the actor is replicated to other clients
involve client rpc which will do it directly just for you
you need to keep it on server if your focus is on listen server and you will be the host
dedicated servers don't need any visual things
im hiding the actor on the server
and showing it on the server
thats how it should be done
server->clientrpc->hide/visible/attach/detach
but it replicates...
switching between tpp/fpp is tricky, you need to keep tpp state on other clients and only change it locally this the point
it will not replicate change if you call clientrpc by server
when you say clientrpc you mean multicast?
if i do this then how will it ever attach to the third person mesh
and how will it set the actor visible on other machines
why you need to hide on other machines?
other machines don'e need to seee you with arms
im spawning in a gun on the server... it needs to be hidden everywhere
you spawn the gun only when you first pick it up, later just play with it
don't need to respawn it
im spawning the weapon in on the server
then hiding it
btw i only set my equipped weapon via a server rpc
bad design
you don't need many hidden weapons attached to the character
i see you only set visible the equipped weapon
so my hotbar is basically a bunch of hidden weapons except the equipped one
when i change my equipped weapon, i set it visible
and the rest hidden
that's bad design, you only need data of those guns, when you need to use one of them just spawn it from the data and destroy the old that you want to hide
theres a ping delay when switching between items
that means id have to spawn it in everytime in my hotbar
yeah it will be good system
for my inventory, i store just the data, and if i add it to my hotbar, i spawn it in
since the hotbar is just 5 items
keeping 5 items spawned in shouldn't be a problem
makes it faster when switching weapons
Yeah you basically just have a 5 actor object pool
but anyways, what could be wrong with my current setup that causes the wepaon to be invisible on the first person mesh just the first time between switching?
exactly
https://gyazo.com/40500b972e963b36d6fe93c42ef7222d
as you can see, on the first switch its visible on the mesh but not the arms, unless i go back and forth
5 weapons max and this is perfectly fine IMO
I wouldn't use an rpc though. Probably best to use a replicated property
im using a onrep equipped weapon variable
Ok that's good
server rpc to just set the equipped weapon
Misread
also, you don't need to hide them, just attach them to different socket on character
that is true
i dont need to hide them
but do i want 5 weapons attached to my character at once?
not really
or 5 objects
whatever it is
maybe theres a better way i can hide them ?
instead of this
That seems fine to me. And disable tick if it's not already while hidden
only thing I can think of that might cause weird issues is that hidden actors stop replicating iirc
yes this is the problem
so once i set it enabled its no longer replicated?
you could set the visibility
let me try that..
just scale it down to 0.01 😄
Yeah that's how I do it in my FPS
you set the visibility?
isn't that what im already doing
is this practical tho lol
why not, setscale3d
how else can you hide a replicated actor
Yes I use SetVisibility.
of the skeletal mesh?
I can just see a bunch of tiny weapons following you around 🤣
Yeah
okay thanks will do.
what about the collisions
does that also replicate
do your equipped weapons have collision?
or maybe they just set the material opacity to 0 😄
Okay my bad I just checked and actually I do use SetHiddenInGame
i was about to say... the skeletal mesh setting did not work lol
Yeah I'd set then to NoCollision unless you want to register bullet hits on them or something
so do you have a hotbar object pool aswell?
do you have it set it hidden / visible onRepNotify changing the equipped weapon?
so after deleting the collision it fixed my issue...
now they are showing visible perfectly fine
and hiding fine
dont know how setting collision can mess it all up but it did
setup a master material with diffuse opacity , expose opacity param and set it to 0 when you need to hide it
No, I use Server and Multicast RPCs, because I'm using client side prediction and sending a prediction key.
Really just sending a weapon cycling index.
ah gotcha
im still having the same issue actually, when hiding it, then setting it visible, it's not showing visible on the first person arms
unless i switch around a few times
On clients only? If so what's your rep notify look like
only on the player switching weapons
it attaches fine for the third person mesh
on the first person mesh it's just floating around the body
not attaching
What's your attachment code look like
When it fails, does it still print that string?
yes
What's this all being called from? Input action or what
Maybe you aren't changing to a valid weapon... instead of just printing "attaching locally", you should use GetObjectName on the weapon itself and see what that is equal to in the instance of a failure.
See if when you swap it's None or something
ill show you a video of what i mean
first switch it glitches then its fine...
always fine on third person mesh
Oh I see it's already there (object pool, duh) just not attaching.
Maybe instead of Attach Actor to Component try Attach Component to Component using the weapon's mesh component
but u see it only glitches on the firsxt switch for the arms
after going back to it, it works
and it works always on the third person mesh
Yeah that is weird
I don't know if there's an possibility that socket name is wrong the first time but it could be something you could print string to see.
Looks like it attaches (it's following) it just has an offset
yeah
it connects fine after switching a few times
just not on the first switch
i have no idea whats wrong or how to fix it lol
could it be some sort of delay issue
I do detach the old mesh first
And I use the SKM class's attach function
Mesh1P->AttachToComponent(PawnMesh1p, FAttachmentTransformRules::KeepRelativeTransform, AttachPoint);```
before setting invisible you detach/?
I set Hidden in Game right before
u set hidden in game then detach?
void AWeapon::AttachMeshToPawn()
{
APawn* MyPawn = GetInstigator();
if (!IsValid(MyPawn) || !MyPawn->Implements<UPlayerInterface>()) return;
// Remove and hide both first and third person meshes
DetachMeshFromPawn();
// For locally controlled players we attach both weapons and let the bOnlyOwnerSee, bOwnerNoSee flags deal with visibility.
const FName AttachPoint = IPlayerInterface::Execute_GetWeaponAttachPoint(MyPawn, WeaponType);
if (MyPawn->IsLocallyControlled())
{
USkeletalMeshComponent* PawnMesh1p = IPlayerInterface::Execute_GetSpecifcPawnMesh(MyPawn, true);
USkeletalMeshComponent* PawnMesh3p = IPlayerInterface::Execute_GetSpecifcPawnMesh(MyPawn, false);
Mesh1P->SetHiddenInGame(false);
Mesh3P->SetHiddenInGame(true);
Mesh1P->AttachToComponent(PawnMesh1p, FAttachmentTransformRules::KeepRelativeTransform, AttachPoint);
Mesh3P->AttachToComponent(PawnMesh3p, FAttachmentTransformRules::KeepRelativeTransform, AttachPoint);
}
else
{
USkeletalMeshComponent* UseWeaponMesh = GetWeaponMesh();
USkeletalMeshComponent* UsePawnMesh = IPlayerInterface::Execute_GetPawnMesh(MyPawn);
UseWeaponMesh->AttachToComponent(UsePawnMesh, FAttachmentTransformRules::KeepRelativeTransform, AttachPoint);
UseWeaponMesh->SetHiddenInGame(false);
}
}
I attach component to/from component, you are attaching the actor which will defer to the weapons root.
What is your weapon's root - the mesh? Or a scene or something else
yeah just default scene root
Yeah it shouldn't matter but you can try Attach Component to Component - though idk why you don't have it working properly just the first couple times 🤷♂️
detaching from component didnt work
i get the same issue where it floats around the first switch
could it be a delay issue?
i dont see what else
But what would it be skipping that a delay would compensate for?
I have no clue
Neither did the guy yesterday
we r all just as confused
There has to be a diff way to do this then since other people have object pool hotbars
If anyone has had an issue like this please let me know how to fix 🙏
(First switch doesn’t attach then second switch does…)
maybe your OnRep is getting called on the client before it's possessed the pawn so the IsLocallyControlled fails and that Current Weapon variable doesn't get set for the first weapon?
impossible because im getting my print message
note when i do this on my server game instance, this doesn't glitch at all. it works fine
Is that weapon a replicated actor?
yes!
Are you aware that actor attachment is replicated by the engine already?
So if you start attaching it locally you will get that and the replicated attachment fighting each other
but the weapon im switching to isn't "attached" yet
its just spawned in
i spawn them all in, hide them, and attach the equipped weapon
i set the rest to hidden
Hiding the ones that aren't important isn't a problem I guess. Idk if you are trying to attach weapons to different parents based on first person vs third person
Cause that would need c++ in theory.
i am attaching to arms if locally controlled and mesh if not
but the thing is, it works after i switch a couple times, just not the first time
Hm yeah that's basically gambling
I did see the gif
Because if you attach a replicated actor on the server it will replicate to clients
There is code in the actor class that handles replicating attachment info
hmm
Which means by default a replicated actor can only be attach to one and the same parent on all players and server
i see what you are saying
You'd need to either attach a non Replicated dummy
so it would be impossible to split between first person and third person in this scenario
Or override the OnRep_Attachment in a weapon c++ class to not do that
As long as you attach the actor on the server and it's replicated, yes
its not being attached on the server though
because this onrep is being called on the server, and on all clients
when i change my equipped weapon (through a server rpc) it triggers this
OnReps trigger on the server too.
yes
so in the onrep i filter the server to do the hiding / showing
then i do an is locally controlled for the attachments
which is why i dont understand why its not attaching locally even if its printing the message
If this is your "filter" for the server then after the branch at the end there the server will be attaching it.
so before the is locally controlled just check if has authority
and if false continue ?
oh wow that fixed it
thanks man
i forgot that is locally controlled doesn't just filter the server out
Just remembrer you can't use that replicated actor for any game logic because it won't be in the expected spot on the server.
wdym
It's not attached on the server.
r u saying like collisions?
So it won't be in the same place on the server.
Anything about it.
Position/rotation
can u give an example where that might be a problem?
Shooting the gun.
If you want to know where the barrel is VIA a socket on the gun, the gun won't be in the player's hands.
As long as you remember that you can't use the gun's location/rotation in any game logic, then it should technically be fine.
On the server it won't be in the location that it's showing on clients.
where would it be on the server?
Wherever you ended up spawning it on the server.
ah
so here
where does the server usually spawn in guns on a fps?
the first person character or the 3rd person character
ig with this logic the gun isn't following the character on the server
tecnhically
itll just spawn in there
What exi was saying though is attachment is replicated so you'd really only need to do the attachment on the server. Doing it on both is the gambling part.
which is why i can't attach it on the server + have it on third person & first person
Attaching a replicated actor on the server will replicate that attachment to clients
Oh you have the same mesh for first and third person. Gotcha
On the weapon I mean
my weapon is just an actor with one mesh
could i run into a problem attaching the weapon only on the clients and not the server you think?
Datura already pointed out the issues with that
My weapon has two meshes, just like the character. One is for the 1st person and one for the 3rd person and they are attached separately.
Mainly because it was originally based on the UE4 ShooterGame sample project. If I looked at it today maybe I'd do it differently.
Maybe not.
welcome to the show adriel
Wait a second, actor attachment is replicated, is component attachment?
You could have a root scene component in your weapon, then just in the first person case, attach the weapon mesh to the first person arms.
That would play nice. If my assumption is correct that actor attachment is replicated but component attachment below that actor is not necessarily replicated
You would end up with, on all machines, the weapon actor is attached to the third person mesh, but on your machine, your weapon actor's mesh is attached to the first person mesh.
and on the server?
All machines
ok
With two separate meshes I don't have to worry about a race condition between attachment replication and rep notifies
@cerulean barn show the component layout of your weapon
Yeah so attach actor just attaches the actor's root component. Just see if you could then attach the skeletal mesh to your first person mesh in the locally controlled case
Unless the client attaches the mesh before attachment replication gets to the client
i can try that.
Overriding OnRep_Attachment in C++ could prevent that as exi said
Would that break the attachment of non-root components? I haven't done any of this shenaniganry myself.
My project is designed in such a way that everyone gets to see the same thing all the time and there's no problem.
Well, give it a try and get back to us. I personally would do it different (and have) and what I did works but hey give it a try. I just think that sharing one weapon mesh between two character meshes, when the weapon is replicated, is not deterministic and will just result in this bug.
override it to do what
Well, say on the server you attach it to the third person mesh. Then in OnRep_Atrachment, on the locally-controlled client, you attach it to the first person mesh.
That's the only way to surefire get it to behave because the attachment has already replicated and won't clobber your first person attachment
Have you tried it yet, you don't even know if it works.
nope i havent tried it yet
idek how to override it, ill have to figure that out first lol
Personally it feels like a hack to me.
Try what I was talking about, you could do that in about 30 seconds in blueprint. If it works it works, if it doesn't then you're no worse off.
try attaching the skeletal component to the arms?
not the actor?
sure i can try that
I would have thought attachment replication would be under under replicate movement since it pretty much is a movement related property but it's probably been like that for 20 years
it worked
this is being ran on the server + all machines
so there shouldnt be a problem with this
You're probably clobbering yourself a little bit because what happens on the server is what happens on the client since attachment of an actor is replicated, but it should technically work as is.
I guess that works since it's the scene root attached on the server and the mesh attached on the client. Seems a little hacky but if it works it works
It's hacky, your final setup will probably look a bit like overriding OnRep_Attachment, so you can just attach the gun actor to the character actor on the server, and it'll attach to the correct component on each machine based on if character is locally controlled or not. But that'd be C++ only
so i wouldnt be able to do that with blueprints &c++
You'd do it once in C++ and forget about it, but if you don't have any C++ in your project at all just put it on the back burner until you do.
It'd be simple:
OnRep_Attachment -> is the thing we're attaching to a MyCharacter? -> yes -> is that MyCharacter locally controlled? -> yes -> attach to its arms
-> no -> attach to the 3pp mesh
You'd need your weapon and character base class to be in C++
ohh
yeah later issue
would i still be able to have a firing animation from the first person view tho?
for now
and like a reload etc
all that's possible
okay great
my fire logic which is in my weapon event graph
why isn't ros_fire being called when a client shoots a gun?
only when the server shoots a gun does it call.
And who's the owner of the actor?
is it not the first person character
Hey guys, I'm wondering I want to handle savegames, now I was thinking a subystem would be nice, until I realized it won't be replicated 😦
I still like the idea of having a subsystem for it but since they are not replicated, I was thinking of maybe having the subsystem calling a function on things like the game mode or something, that then will call a server sided function that then calls the subsystem on the server side, but not sure about that, since it feels a little complicated.
What do you say, how to handle that, so that I also have a nice way of accessing it.
gamemode is only on server and you can only call RPCs through owned actors, what's the goal here, what does a client send the server?
So now it is "save game" and "load game", maybe later download/upload the save game.
Basically everything, in the long run there will be two things, but it's the players inventory/abilities/... and then another thing will be the current levels state.
You can do all that local and then have a RPC in PlayerController to upload a build or whatever to the server
But I will 100% run this on the server, especially for loading the savegame, since I was already running into the issue, that adding inventory items on the client will ofc not be replicated ^^
I said local
server has local too
The only thing that has to cross the network is a client telling a server some data about something they did previously, like a saved build or whatever
But I was thinking I can have a Server function on the player controller, or smth like that, since it will also allow me to check if the player has rights to do that correct?
I don't understand fully, what do you mean by build?
Like say an ability build
oh that is already on the server anyway, since it has authority on it.
Then what is the problem, what needs to go across the network here from client to server?
If you're talking about something like Minecraft with server sided inventory then it's just like any other game, the server saves and loads the savegames
The question is where do I put the code to not fully spread it out over the whole project ^^
Gamemode probably
that's where player connections and getting their pawn and such happen
I currently use a subsystem for it that works really nice, but it is not replicated 😦
yea but the call "start saving" is done on the client
the things that happen as a result of loading a game will be visible to clients through replication of various things
so I would at least have to wrap it in a custom event that is called on the server
PlayerController:
Input -> run on server event
run on server event -> call SaveAll
do i need to set the owner of the weapon when equipping it?
the client isn't doing any saving, it's requesting that a save be done on its behalf, serverside
You need to own something to call RPCs through it
you can either have the local gun ask its serverside gun to fire, or have your local pawn ask its serverside pawn to fire MyGun
^^
but maybe i have to just live with the server event
won't happen, subsystems don't replicate
your client can load a game, sure
in the bp first person character class the equipped weapon is a component of it, so doesnt it already own it?
but it'll only be on their machine
do you mean child actor component which spawns the weapon actor?
do you have to set the owner when spawning it?
if child actor component doesn't do that already, then yes
Yea that's why I was thinking, what if the subsystem calls a server function on the game mode which then in turn calls the subsystem on the server.
But not sure if this will just add more complexity.
are you using child actor component?
gamemode only exists on server anyway
there is no game mode on clients
read the compendium
my equippedweapon is just a variable for my bp first person character
which is a bp_weapon actor
With the previous information about Unreal Engine's Server-Client architecture and the common classes we can divide those into four categories:
Or something else maybe the player controlelr idk but you get what I'm saying right? ^^
uhh nice
show how it's spawned
the server is doing the spawning
so i assume its not setting the owner
yeah set owner to self
I prefer to not have rpcs in things beyond pawn though
how would you do firing logic then?
Input -> rpc
rpc -> tell MyGun to fire
you will have lag like that though, this is why shooters are hard. you can do some stuff like locally telling it to fire too
what am i setting the owner to self? the spawned actor?
you are saying that the spawned actors owner is self (the thing doing the spawning which is the character right?)
client already owns the character
why doesnt it do that automatically
because you don't always want all things you spawn to be owned by you
yeah that fixed my issue though; thanks
thts true
just wondering since this whole tutorail i followed was pretty shit (apparently)
is that a bad way to do it
this right here
they all are
ive come to notice
not literally, but if you're new, you can't tell the difference
yeah i had no idea
until i had to redo the whole weapon system
he had them all as components
not actors
You're gonna redo it many times in the future
just get good at coding lol
but im getting a better understanding of whats going on
I've redone my vehicle system 5x now
so the thing is, i already know how to code in c++ and shit but not in unreal
everyone told me to start in blueprints
but i like coding more than this stuff
It's a good idea to get a feel for how the engine is set up, then go digging into C++
would i have to restart?
if you don't know the difference between an ActorComponent and SceneComponent and UObject and Actor and GameMode and GameState you'll be absolutely lost on the C++ side
but once you know the architecture it's really not that bad. It's like if C++ was trying real hard to be C#
nah just move stuff to C++ as you go
start with a single file that has your project structs and enums and a BP function library
Then you can start making your own components and base actors
yeah i still dont know the diffference between everything
so i should prob just keep messing around until i get more comfortable
its only been a couple weeks ive been doing this
Say you're making a simple basic shooter, you'll at least end up with a c++ base class for your game framework classes and your pawn and your weapon
So for instance an AK47 might be like:
UObject -> AActor -> YourWeaponBase -> BPYourWeaponBase -> AK47
( C++ )( BP )
edited
i see that but it needs both bp and c++ base?
not needs but it's nice to have
you can prototype in the BP base then move functionality to the C++ base when it's fleshed out
eventually the BP base will be damn near empty
you think i should start that stuff now or when im more comfortable
Here's what you have right now:
UObject -> AActor -> BPYourWeaponBase -> AK47
( C++ )( BP )
I'd start out making a C++ types file anyway
i dont fully understand, in the same project?
like the c++ files
or would i make a new proj
What starter project did you start with?
you can do that
the first person template + third person template
already had to do that
I'd make sure your IDE is set up first though, I recommend rider
when i implemented lobby system
oh then you're set
i just use vsc for c++
fire up your IDE and make a new BPFunctionLibrary file
You're off the beaten path but you should be able to get it going
what would this file be for
start putting all your types (structs and such) and a BPFunctionLibrary in it
that's how you make your own nodes
once you get comfy doing that make your own base classes for character and weap and such
i understand u can make the base classes in c++ but wdym u can make your own nodes
i dont even have a structure setup for anything yet
for the inventory i just have weapons setup for now
okay i understand you can create custom nodes but wouldnt i just be using the nodes already created?
or are there some things you cant do with the "provided" nodes
got it
and for safety you want to put your custom structs in C++ is the general wisdom
BP structs can break in really bad ways
and this will get you used to doing Unreal stuff in C++
so u test stuff in bp and if it works u convert to c++?
yup
like i should be converting my base weapon and base first person character into c++ classes
I mean if it's simple I jsut start out in C++ but I'm much much faster in BP
Or just keep it in BP
id prefer to code then keep nodes honestly so why not
yeah it all depends on what you're trying to do
i like coding more than this
it's all programming
yea
just typing vs drag and drop really
wouldn't
like built in stuff
like event begin play etc
ah so you can only create custom nodes
the BP layer is kinda your final hook things together and do visuals layer
so use c++ to do logic, and hook that logic into the bps
It's not an either/or decision. Learn what makes C++ and Blueprints different, what they have in common, and how to use them together effectively. We'll also learn a thing or two about performance optimization and some basic software design concepts.
Read the article version: http://awforsythe.com/unreal/blueprints_vs_cpp/
00:00 - Introduction...
ill check that out
give that a watch
he explains how to use them for custom nodes & base classes and stuff?
He explains the philosophy around what typically goes where
ok
working in Unreal with zero BP is insanity, as is working with zero C++ if you're doing anything anywhere near complicated
you'll at least have some data-only BPs most likely
when picking an engine i was almost against unreal just for the blueprint aspect
as i enjoy coding
but i came around
I like programming, whatever gets my ideas into logic the fastest. I'd do things 100% with BP if it was exactly as capable and performant, but it's not.
yeah i agree
It's about 100x slower, that doesn't really matter for press button -> call Jump, but it matters for Tick -> 5k lines of code
Hey everyone, I have a very beginner question. I have watched a lot of videos and read documents about general replication with actors and events and things, but I am having a hard time finding good, thorough resources about game mode / game state / player state / etc. I don't know how to tell when I am putting too much on the game mode and when things should be delegated elsewhere. For example I could have a match timer in the game mode that is constantly sending to game state to be replicated each second, or it could just pass the max value for the timer and each client can count down on their own. Things like that, where to store variables, do certain functions, etc. are a bit hard for me to understand where they should belong. Does anyone have any good resources? I found a couple in the pins but would love some more if there are any!
Say you were making a bullet system that did heavy simulation like Arma. That's C++ territory, it'll work in BP but be hella slow
If you're just doing a few things on begin play of an actor, that's fine in BP
yeah makes sense
slower but more easily accessable and less complex
bps ^
Also any time you're dealing with assets, you wanna be in BP
you don't want to be typing out asset paths in C++, that's a huge smell
your C++ weapon can have WeaponMeshComponent, but BP is where you say what mesh WeaponMeshComponent should use.
Just remember that this is kinda one-way, BP can call into C++ but the other way around is not very advisable
calling into overridden stuff is fine, but if it's declared at the BP layer it lives at the BP layer
understood
I’ll definitely check that out tonight and try to convert my base classes to c++
PlayerState = An actor meant to house information relating to a specific player regardless of what pawn they may be possessing. Good for things like Player score, name. It replicates to all, always.
GameState = A replicated actor that can be used to house information pertaining to the game that is easily accessible via "Get GameState". Good for things like Timers, Team Scores. Replicates to all, always, so it's good for general information pertaining to... the state of the game.
GameMode = A non-replicated actor responsible for handling the spawning of players and is responsible for handling details about what other default classes to use. Sometimes refered to as handling the "rules" of the overall game. This actor doesn't get replicated to clients.
But just to reiterate , I keep the bp first person for event begin play, and I call the custom c++ nodes in it ?
I’m sure the video will explain, so I’ll have to check that out
All the nodes you have access to in BP ARE written in C++
yes
GameMode = Should have been called GameController to keep the Controller/State energy going
why is the pitch not the same on server/client?
void UARMAAnimationInstanceBase::NativeUpdateAnimation()
{
Speed = Character->GetVelocity().Length();
Direction = Character->GetCalculateDirection();
FRotator DeltaRotator;
const FRotator CharacterActorRotation = Character->GetActorRotation();
if (Character->IsLocallyControlled())
{
DeltaRotator = (Character->GetControlRotation() - CharacterActorRotation).GetNormalized();
}
else
{
DeltaRotator = (Character->GetBaseAimRotation() - CharacterActorRotation).GetNormalized();
}
Pitch = DeltaRotator.Pitch;
Yaw = DeltaRotator.Yaw;
}
according to the docs they should be the same since GetBaseAimRotation is intended to return a replicated local pitch!
So technically c++ coding is just coding nodes
or it has something to do with aimoffset animations?
Not just, but C++ that's usable in BP IS the nodes
What else is it used for then?
that's where the nodes come from
You can do whatever you want in C++
Because you can’t have only a base class because u can’t have the event begin play I thought
what
So the Game Mode should only be used for really fundamental and core processes / values but most of the general game loop will be in game state? Pertaining to various games with mode-based systems and multiple gameplay states like rocket league, call of duty, etc
Every actor has a Begin Play somewhere
my earlier question was how to code the event begin play or shoot interaction
I interpreted you can only do that in bps
You can, and you'd base them off of ACharacter and AActor respectively.
Yes, you can put all the logic and stuff in C++.
You'll still want some data only BP subclasses (or data assets) to say what meshes and sounds and animations to use)
Fire -> play FireSound -> spawn bullet //C++
FireSound = Gun.wav //BP
Got it
watch that video
load object is also a good option to avoid refiling those in bp if the class gets corrupted 😄
LogTemp: Server Pitch: -19.308472
LogTemp: Client Pitch: -26.823709
LogTemp: Server Pitch: -19.308472
LogTemp: Client Pitch: -26.823709
LogTemp: Server Pitch: -19.308472
LogTemp: Client Pitch: -26.823709
LogTemp: Server Pitch: -19.308472
LogTemp: Client Pitch: -26.823709
LogTemp: Server Pitch: -19.308472
LogTemp: Client Pitch: -26.823709
LogTemp: Server Pitch: -19.308472
LogTemp: Client Pitch: -26.823709
LogTemp: Server Pitch: -19.308472
LogTemp: Client Pitch: -26.823709
LogTemp: Server Pitch: -19.308472
LogTemp: Client Pitch: -26.823709
LogTemp: Server Pitch: -19.308472
LogTemp: Client Pitch: -26.823709
LogTemp: Server Pitch: -19.308472
LogTemp: Client Pitch: -26.823709
LogTemp: Server Pitch: -19.308472
LogTemp: Client Pitch: -26.823709
LogTemp: Server Pitch: -19.308472
LogTemp: Client Pitch: -26.823709
LogTemp: Server Pitch: -19.308472
LogTemp: Client Pitch: -26.823709
LogTemp: Server Pitch: -19.308472
LogTemp: Client Pitch: -26.823709
Epic Games what is going on? 😄
this starts happening when the equipped weapon is set to SetViewTargetWithBlend by character
because of this small difference the bullets hits the wrong target the red dot above the aim point
Hello, what is the correct approach to make my character look at its target in a multiplayer environment? Does the Character Movement Component (CMC) provide any built-in method for this? I would like to avoid sending RPCs every tick if possible. Thanks!
I think my dumb idea would depend on the level of accuracy and responsiveness needed
I think just sending the target it's looking at would work great as a first try because that way it doesn't need constant updates, just what it is looking at
but I'm not sure if the target is a replicated object or just an arbitrary point in space
aim pitch is not replicated
for whatever reason
did it recently change?
yes in 5.6 they moved to another property
is 5.6 out
it is very imporant you override GetBaseAimRotation and GetViewRotation to do what you actually want imo
nope
I'm on main and I'm amazed this got changed
seems like something they would never touch
it was pretty shit considering it entirely breaks if you have a player oriented a direction other than up
the shrimple thing imo is to just have a separate aim rotation entirely
also this is more advanced and not needed for most projects but having your entire pawn replicated movement and state happen in one struct removes a ton of headaches from property replication
there is no chance you get it split into multiple packets when it is one dumb unga bunga struct
hmm I don't think there's anything stopping a struct from replicating it's parts separately
this is mostly for things that MUST be known together, for example if crouching moves you and you receive the moved transform before the crouch you WILL jitter
show me in Iris where you can split up quantized types in a packet I guess? I'm all ears
you can definitely delta serialize but it will consider the parts in whole
I know nothing about iris
if the parts are distinct network objects yes they will be sent seperately, but I think POD types that aren't network references are sent atomically
I assume the old replication actor channels make a similar gaurantee but I'm not sure
(you don't need to use iris yet, it's still quite experimental but serves as a drop in replacement unless you use the replication graph)
there's a atomic specifier but I can't remember what it does
really? I want to see it
nothing seems to use this
https://vorixo.github.io/devtricks/atomicity/#default-struct-replication
ah, you are correct that earlier versions do indeed split up properties
my fault for being too used to iris
the simple thing is to just make a net serializer
which is easily done in the old setup
Iris doesn't do atomic struct rep?
Iris net serializers are frankly 10x more complicated than they need to be... they really should have a "simple" mode
yes it does
by default
with delta flags per member (if it can delta serialize the type)
it is still sometimes needed to make custom serialization if you have something where you can preclude sending large amounts of other things
or send things that aren't replicated at all
Iris will warn if you use a struct that has old custom serialization but not a new iris one
@twin vessel yes if you make a custom serializer that responds to stuff changing (in iris you could arguably make a new fragment but... I don't even know how to make that work well)
frankly... just make an onrep and compare the previous with the current
you don't need to get fancy to just check one one small thing changes each time its received
assuming its not an extreme number of properties
I would rather keep everything inside the struct for sake of clean code, unless it is bad practice.
How would you know which member is replicating from the serializer?
"for sake of clean code" is entirely beside the point here
the serializer would know which member is replicating by just reading the bits
when you write it, it probably changed and you can just do whatever
for example fast array serializers work that way
but seriously... just use an if statement lol
unless it is extremely expensive to compare the two or you need some special case
I don't even know what this struct looks like so I can't really compare much
you might need to make a custom equality operator for the type but that's easily done in most IDEs with one click
The objective was to have a struct that i can just add to an UObject to act as a small component
hmm... yeah unfortunately property replication kind of assumes the owner has ufunctions
this feels wrong
this is really dumb I think and internally to me there is no reason you can't replace it to use function ptrs
Was hoping to do something like what fast array does
dumb structs are not wrong, that is just what they want to do
they are far less complicated than allocating an entire lifetime'd object
that said this is going to kind of fight the assumptions unreal makes
yeah... the way that works depends on which replication you use
What do you mean by which replication?
TFastArrayReplicationFragment has a CallRepNotifies but I will insist that this will be tedious to figure out how to make your own... Iris has some absurdly obtuse boilerplate
that's what Iris does
for the regular setup I don't know, I would just breakpoint the fast array callback
FWIW you can get 90% of the way there by just forcing the things that include that struct to do a tiny onrep for boilerplate that calls something on the struct or whatever you want
Hi, i am trying get the proper rotation of my characters, for some reason it's not translating properly. (have not started handling things with C++ yet, just blueprints)
you can also mark parts of a ustruct with NotReplicated to have only part of it sent in the packet (or just make them... not uproperties)
Yeah this is also an option i guess
Well thanks for the insights, i will give a look to how fast array does it, but at this point i might actually go for this solution or stick to UObjects
you might want to change the pawn to face their control rotation
this one?
try it out
it wasnt it :/
is bOrientRotationToMovement enabled?
Hello everybody!
I am working on a multiplayer game using the steam api. I watched a view tutorial videos about adding the Advanced Session Plugin and got that set up successfully. I am currently able to connect two clients using ASP. But i ran into a problem when in multiplayer regarding my item pick up / throw down actions.
Whenever the Host picks up / drops an item it is replicated successfully, meaning the connected clients get the deleted / added items replicated. However when a client attempts to do so, the items are not getting removed from the world when picked up and also not added when dropped.
I already watched several videos for replication, but could not figure out what the problem is. I was also not able to find replication issues involving ASP.
Does anybody have any experience with ASP and replication issues? I've had this problem for weeks now and cannot solve it.
These are the tutorials I followed for impkementing ASP and trying to resolve the replication issues:
ASP setup: https://www.youtube.com/watch?v=5nMKEKV0acI
Replication basics: https://www.youtube.com/watch?v=bBK8A-mFH-s
ASP won't have anything to do with it
Replication works the same regardless of whatever session backend you use
99% of the time you should almost certainly be able to reproduce the same issue in editor.
As above, the session backend does not change this. The host can do whatever they want because they're the host, but there's likely something fundamentally wrong with your pickup system
So you would need to show that to us
In all likelihood, you've called a server RPC on an actor that client player does not own
This is the chain of function calls and events when a player picks up an item. before the RPC_Server_DestroyItem is called the item is being added to the player's inventory at the currently selected slot.
How do i check whether the client owns an actor?
Yeah I'm not surprised this doesn't work properly
Is the only interaction to the server just telling it to destroy the actor?
Like I said, not surprised
Inventory management should also happen on the server
It should be server authoritative
And yeah, the RPC doesn't run because the player doesn't own that actor. As a client, you cannot call server RPCs on actors you do not own
ok, thank you. that helps a lot already
would there be an easy fix for my inventory system or would it be better to start from scratch with server-side handling in mind?
Based on the information I see, it probably would be better to redo it. This really looks like something that was designed for singleplayer that you tried to make multiplayer after the fact
Which you should never do
Yeah, i followed a starter tutorial for inventory management intended for singleplayer and apparently understood multiplayer wrong. i was thinking it would be as simple as telling the game "you are now multiplayer" but my assumption was completely wrong as i now know.
Thank you, though. Now i finally know what the issue is.
I will rework the parts i did without multiplayer in mind.
Okay, this is weird..when I "Play as client" then this does call the OnRep-function on the Struct_Equipment
When I make a cooked build, this doesnt OnRep and I have to this:
Does someone know why?
presumably set members in BP doesn't call the OnRep
but you'd get as play as client because you're a client receiving a replication change
if you're the server, you wouldn't
in C++ land, it's a pretty typical pattern to manually call the OnRep function, and it seems like that's what you'd have to do here
well but i am getting the OnRep on the client,so the server must have "done the change".....
ive asked grok and it seems that there just is a difference between cooked builds and editor.
just another quirk of UE 😄
ive asked grok
oh dear
and yeah, if you change a replicated value on the server and it's replicated down to clients, you'll get an OnRep as part of that process
i mean i figured out how to fix it anyway...i just wanted to see if theres a "logical" explanation for it to be this way, as you would think "if it works in editor,it works in built environments too"...well at least as someone who is still a newbie 🙂
exactly, but as ive said, its 2 different outcomes from the same code 🙂 thats confusing
"play as client" is supposed to emulate a dedicated server setup. so if you're testing in singleplayer, or you're a listen server host, then there's no replication at play there
i see, that could explain it, yet if i do the "set w/Notify" it actually does do the OnRep, but i guess internally as a listen-server-host it just is a "set variable"?
"set w/ notify" is what BP provides which is basically just:
OnRep_Value();```
under the covers
yeah. okay. well then i know... gotta set the entire variable after i set members inside of it, got it.
and dont be too negative about this 🙂 AI is pretty good for hobby-ists like me. Im 38 and I cant go back to school to learn UE etc. so grok is as close as a tutor as i can get (besides youtube tutorials)
i hear the replication graph is getting phased out or something.. but the actual class it's based on isn't being phased out right? UReplicationDriver
Well if you mean phased out as moving towards Iris, I guess, yeah
Hi, I am making a custom pawn for a random multiplayer project of mine, and for some reason, figuring out how to rotate the skeletal mesh has been a pain, and now, its rapidly changing rotations for no apparent reason, one time it goes to the desired rotation, and another time it goes to the default rotation set in the player blueprint. The PIE session's netmode in the video is set to Client.
This is how I open ADS
void AARMACharacterBase::ToggleADS(bool bWantToADS)
{
if (AARMAPlayerControllerBase* PC = Cast<AARMAPlayerControllerBase>(GetWorld()->GetFirstPlayerController()))
{
EquippedWeapon->OpenADS(PC);
GetMesh()->SetVisibility(false, false);
SKM_Hair->SetVisibility(false);
}
}
void AWeapon::OpenADS(APlayerController* PC)
{
if (!PC) { return; }
const bool bSightAttached = (SightObject != nullptr);
const FVector CamLocation = bSightAttached ?
Optical->GetSocketLocation(FName("ADSCameraSocket")) :
WeaponMesh->GetSocketLocation(FName("CameraSocket"));
const float Fov = bSightAttached ? SightObject->SightFieldOfView : TargetingFOV;
ADSCamera->SetWorldLocation(CamLocation);
ADSCamera->SetActive(true, false);
ADSCamera->SetFieldOfView(Fov);
PC->SetViewTargetWithBlend(EquippedWeapon);
}
void UARMAAnimationInstanceBase::UpdateAnimProperties() //Tick
{
FRotator DeltaRotator;
if (Character->IsLocallyControlled())
{
DeltaRotator = (Character->GetControlRotation() - Character->GetActorRotation()).GetNormalized();
}
else
{
DeltaRotator = (Character->GetBaseAimRotation() - Character->GetActorRotation()).GetNormalized();
}
Pitch = DeltaRotator.Pitch;
Yaw = DeltaRotator.Yaw;
}
BaseAimRotation works fine if the character camera is active, when i switch to the weapon camera it starts bad behavior
You can't arbitrarily change the mesh rotation because character movement does that for smoothing
It will always reset to face the default orientation eventually
I am not using character class, im using pawn class
Well also, both the server and controlling client will be calling RotateMesh, so they'll be arguing over it constantly
you'll also probably have loads of logspam about remote clients not being able to call that RPC because they don't own the actor too
You should guard the call appropriately as a start
I think switching to the weapon camera (or the ADS camera), the normal control rotation flow is potentially disrupting and this is not correctly handled by the engine
Seems like Epic games is more focused on FPP arms which will use normal character aimrotation but in my case i am using totally different approach by using the weapon camera while keeping the tpp mode, so basically looking through the weapon camera.
the system i invented has many pros.
1: no need sync fpp/tpp mesh state since i simply not using fpp mesh for first person view 😄
2: tpp mesh working as fpp when looknig through camera mesh
3: no need to mess with mesh visibility which breaks replication
but has only one bad side, baseaimrotation not working correctly
You didn't invented this system, its already exists and fully supported by UE 🙂
baserot is tied to the local pc control rot in the replicated packed property server reads from your local controller rotation and sends your replicated pitch/yaw state to other clients
you don't need this
if (!Character->IsLocallyControlled())
{
DeltaRotator = (Character->GetBaseAimRotation() - Character->GetActorRotation()).GetNormalized();
}
else
{
DeltaRotator = (Character->GetControlRotation() - Character->GetActorRotation()).GetNormalized();
}
instead do
USTRUCT(BlueprintType)
struct FRotatorDelta
{
GENERATED_BODY()
FRotator DeltaRotator;
FRotatorDelta(ACharacter* Character)
{
if (!Character->IsLocallyControlled() && !Character->HasAuthority())
{
DeltaRotator = (Character->GetBaseAimRotation() - Character->GetActorRotation()).GetNormalized();
}
else
{
DeltaRotator = (Character->GetControlRotation() - Character->GetActorRotation()).GetNormalized();
}
}
};
void UpdateAnimProperties()
{
FRotatorDelta RotatorDelta(Character);
Pitch = RotatorDelta.DeltaRotator.Pitch;
Yaw = RotatorDelta.DeltaRotator.Yaw;
}
compiling will give feedback if it works thanks so much
absolutely working and super thanks solving this issue, i was breaking my head with this from already 2 days
still small tiny difference but it works
That's because the Server only gets a compressed version of the ControlRotation.
Thanks, so it will never be 1:1 right?
You'd need to compress is locally too.
YawAndPitchPack = UCharacterMovementComponent::PackYawAndPitchTo32(SavedControlRotation.Yaw, SavedControlRotation.Pitch);
const uint32 PitchShort = FRotator::CompressAxisToShort(Pitch);
super thanks i will be doing this ofcourse, it seems like i have to override the base aim rotation and make it return the final compress value
Although I'm not entirely sure if that still happens the same way
Might just be the general ControlRotation replication
I will test it later, currently it works as intented and the bullets spawn at correct location
// ControlRotation : FRotator handles each component zero/non-zero test; it uses a single signal bit for zero/non-zero, and uses 16 bits per component if non-zero.
ControlRotation.NetSerialize(Ar, PackageMap, bLocalSuccess);
Or rather the FRotator NetSerialize
But it's gonna be the same stuff
oid UE::Math::TRotator<T>::SerializeCompressedShort( FArchive& Ar )
{
const bool bArLoading = Ar.IsLoading();
uint16 ShortPitch = 0;
uint16 ShortYaw = 0;
uint16 ShortRoll = 0;
// If saving, we need to compress before writing. If loading we'll just serialize in the data so no need to compress.
if( !bArLoading )
{
ShortPitch = TRotator<T>::CompressAxisToShort(Pitch);
ShortYaw = TRotator<T>::CompressAxisToShort(Yaw);
ShortRoll = TRotator<T>::CompressAxisToShort(Roll);
}
uint8 B = (ShortPitch!=0);
Ar.SerializeBits( &B, 1 );
if( B )
{
Ar << ShortPitch;
}
else
{
ShortPitch = 0;
}
if( bArLoading )
{
Pitch = TRotator<T>::DecompressAxisFromShort(ShortPitch);
Yaw = TRotator<T>::DecompressAxisFromShort(ShortYaw);
Roll = TRotator<T>::DecompressAxisFromShort(ShortRoll);
}
So just something like this should work:
void UpdateAnimProperties()
{
FRotatorDelta RotatorDelta(Character);
Pitch = FRotator::DecompressAxisFromShort(FRotator::CompressAxisToShort(RotatorDelta.DeltaRotator.Pitch));
Yaw = RotatorDelta.DeltaRotator.Yaw;
}
Or wherever you need that
yeah i got that, i will test it now in few minutes
uraaa it works 🫡
but there is an issue, it can't get to negatives 🤔
and character always looking upward
For a server function, is it possible to get the client/player that was calling it?
You'd need to check if the CMC does anything else afterwards with it
There is not really a reason for it to drop the -
hmm Ok
Just wondering how I could validate, if a client that is calling a server function, has permission to do so, or do I need to create a key and send it with the request?
pass param type of character?
I want to check if a client has the permission to call a function on the server, but I don't know how I know which client was calling the server function
if(HasAuthority())