Yes, makes sense now.
Try my last suggestion and lmk how that goes.
Cast to your character from inside the projectile.
Use the same “onComponentHit” node but inside projectileBP
and cast to your characterBP from “hitActor” then call “death/kill”
The way you have this setup is checking your character to hit bullet, not the other way around.
OK, I will try it tomorrow after I get home from work. I used to have it this way but decided to change it because it felt weird putting too much code inside the projectileBP but I didn’t have the above mentioned server and then client calls.
Thanks for the help!
One other thing to mention could possibly help solve this - the server cannot see the projectile the client shoots but the client can see the projectile from the server, weird?
Hmmm.
In your WeaponBP, on fire you are spawning the ProjectileBP correct?
You will want to re-write the spawn code to run thru server/client also.
All these things need to be replicated.
So run on server first and then multicast it?
Yes, make a multicast event for the spawning code.
Call that thru a server event.
Then call the server event where your original “spawnProjectile” code is.
Just quickly tried that - no difference
can you Screenshot your code?
Try setting up the projectile events like Forsaken does.
I think he makes actor object or class inputs on his events.
The selected actor to spawn should be set before the replication events.
But for your damage, almost positive you just need to call the
damage from projectile, not the character.
Sure here it is:
If the player presses the shoot gun button, it calculates muzzle rotation and then starts firing. If they let go of the button, it stops firing.
It then goes into an timeline where the an event to spawn the projectile using the muzzle as its spawn point and is called every 0.1 seconds. The spawned projectile is run on the server and then mulitcasted to all clients.
(I had my own code for doing this part but decided to follow the tutorial anyway - didn’t seem to change anything)
Then the projectile has a capsule collider on it, if it hits anything it destroys itself.
If the players mesh hitbox hits anything it asks if its a projectile, if it is it should play the kill event. The kill event is run on the server first and then multicasts to all clients.
Except, the only player this works for is the server. The client can still not kill anything and the projectiles do not replicate to other clients.
Setting up the damage the way I suggested should work.
I use raycasting rather than projectile but the results should be the same.
You might want to make a new post for the projectile spawning,
as it’s not directly related to the original question. But,
the damage/death code should be called on your projectile,
when it hits the player. Not on the player, you don’t shoot players at bullets.
Your clients shouldn’t have to replicate Kill to the server. Server should detect the hit itself, then replicate Kill event to everyone, ie: what you had initially was better. You might want to replace that IsLocallyControlled check with an HasAuthority check though.
The first thing to make sure of is that projectiles do exist on the server. According to what I glanced through above, that’s where your problem lies.
If I read this right the projectile is only spawned on the machine that is firing. That would mean “SR Spawn Projectile” is not forwarded to server. The flow does seem correct, so you are probably missing one of the replication conditions. Client-to-server replication is restricted to the Owner of the actor, so you want to make sure that :
- BP Weapon Master replicates
- “Equipped Item” is spawned on server/authority, and has its Owner set to the pawn or controller that does the shooting. You can specify Owner in the SpawnActor node.
Another point I noticed, is that in your projectile graph you are destroying projectile upon impact, while on character graph you try to cast to projectile upon impact. While this may not be the source of your issue, it certainly does sound like a good recipe for inconsistent bugs as you cannot predict execution order there. As mikey pointed out, it would be better design to have the projectile apply damage to hit target. Then you can let target handle a damage event (AnyDamage / PointDamage / RadialDamage).