Download

Trying to get Player Character from Camera Component.

Okay so I am about 2 weeks into learning C++ and I have looked and tried to find a good tutorial for what I want to happen but have not had any luck. So I have a targeting system and most of it works, however I want to change the player characters speed once you lock on to a target and return it back to normal upon unlocking. Seems simple and straight forward, except all the functions for targeting are on the camera. So I need a way to effect the player movement speed in the function that locks in and I just can’t for the life of me figure it out. This is what I tried

APlayer->GetCharacterMovement()->MaxWalkSpeed = 150.0f;

Obviously this is not working, can someone help this poor noob out please, even a tutorial on the matter would be helpful

Without knowing what’s not working, it’s not obvious to me.

Though, architecturally, that doesn’t sound like a good method - why would a Camera have anything to deal with a character’s movement? I’d probably want to have somewhere, like perhaps the PlayerController or the Pawn that already has the Camera and the Movement components, as the source of truth for “am I locked on” and “is my movement restricted”.

Its bad decision, and you need to change movement somewhere else.
Anyway, to call something, you should use reference to that.
In this case, inside camera component, you can use:

AActor* MyOwner = GetOwner();
ACharacter* MyCharacter = Cast<ACharacter>(MyOwner);
MyCharacter->GetCharacterMovement()->MaxWalkSpeed = 150.0f;