As I am new to UE4 engine, I ran across a problem casting to players controlled pawn. At first, I was completely puzzled why a component reference variable I was using was not being set. Because this worked fine on server and not on a client, I was certain this was a replication issue (I am still sorting that logic out).
After many trials, I found that issue was not replication but that Event Begin Play was being fired on client before character object was accessible to its controller (client side). To figure this out, I did a quick test controller and linked its Event Begin Play to a character cast (getting self-controlled pawn); it failed every time. Next, I added a delay function and had cast re-fire every tick for up to 5 delta seconds and sure enough, after 1 failed attempt, it casted perfectly.
LogBlueprintUserMessages: Server: Event Begin Play: Received valid character cast after (0.0) delta seconds! LogBlueprintUserMessages: Client 1: Event Begin Play: Received valid character cast after (0.147438) delta seconds!
It likely makes sense that server fired event on client after server had spawned and linked that controller’s character with no regard to client’s pawn state. Is this a correct assumption?
Ultimately, my questions are:
-
is this working as intended and I am just misusing it?
-
If this is a “bad” place to modify controller pawns, where is best place?
I would like to set up multiplayer input controls and functions to be casted/executed on a player’s character without having to duplicate them on every character (movement, camera controls, etc.). I chose to try controller as it would remain same throughout but character may change. Given this sync concern, I am a bit lost.
Thanks!
Edit:
I have done some more testing. further I go down this rabbit hole more confused I get! I added some logic for controller to tell me via string print exactly which controller each message was referring too and exactly how many times it tried. I also set it to run two clients on a dedicated server in same instance and this is what it had to say:
*LogBlueprintUserMessages: Server: TestController1 Failed cast attempt 1.
LogBlueprintUserMessages: Server: TestController1 Event Begin Play: Received valid character cast after (0.0) delta seconds!
LogBlueprintUserMessages: Server: TestController2 Failed cast attempt 1.
LogBlueprintUserMessages: Server: TestController2 Event Begin Play: Received valid character cast after (0.0) delta seconds!
LogBlueprintUserMessages: Client 1: TestController3 Failed cast attempt 1.
LogBlueprintUserMessages: Client 1: TestController3 Event Begin Play: Received valid character cast after (0.283715) delta seconds!
LogBlueprintUserMessages: Client 2: TestController4 Failed cast attempt 1.
LogBlueprintUserMessages: Client 2: TestController4 Event Begin Play: Received valid character cast after (0.283715) delta seconds!*
I am very puzzled as to why TestController1 and TestController2 are printing out failed cast attempt and then a success attempt at 0.0 which would mean it never hit a cast failure?… facepalm. only thing I can figure is that this has to be some type of instantiation order in engine (i.e Controller → Pawn) that is causing desync; but that begs to question why server is innately looping cast but client does not.