Download

Replicating Turret Rotation

I’m currently working on a project to further familiarize myself with how replicating stuff in UE4 works, thus I’ve set out to make a basic vehicular shooter game. However, I’ve already run into an obstacle when it comes to replication. I’ll try and describe how I’ve set it all up to the best of my ability. These are the blueprints I’ve currently set up:

Jeep - This is a custom vehicle based on the advanced vehicle BP. Nothing too important here other than this is currently what controls the weapon rotation using the MouseX and MouseY input events*(thought this made sense since they’re local events)*.
BP_MountedWeapon - This is a BP I’ve made whose SkeletalMesh is changed depending on an enumeration which is exposed on spawn.

Weapon Attachment

Currently for testing purposes since I only have one weapon, one BP_MountedWeapon is spawned on BeginPlay and attached to the Jeep using AttachToComponent.

Weapon Rotation

The camera for my vehicle is doing a linetrace every tick, shooting forward. I am then using the TraceEnd location to find the look at rotation for my mounted weapon.

Rotation Replication

This is as far as I’ve got, I’ve tried my best to research how this works but I’m rather confused as to how the logic works on UE’s end. I’m familiar with the whole authority thing, where the client shouldn’t be trusted.

My current setup works like this;

Where S_UpdateWeaponRotation is executed via the WeaponsLookAt function. Obviously it works locally, however, nothing is being replicated.

I’ve also tried having a replicated rotator variable in BP_MountedWeapon, which is attached to a notify function and try to update it via that - however, that didn’t work either.

Any pointers in the right direction would be greatly appreciated :frowning:

Edit:

I was able to fix this myself, by doing the rotation directly via the Jeep BP instead. As for why it wasn’t working with the method I tried above I’m not quite sure, probably some ownership issues due to it being attached? If someone can give me a proper explanation as to why - that would be greatly appreciated!

If anyone is curious, this is how I set it up to finally get it working;