I feel like I’m making a grand oversight somewhere, I’ve searched allover for this and I can’t find a happy answer anywhere, so I’m hoping the c++ guru’s can help me out here.
I’m writing an RPC call in my c++ class that passes an AActor pointer as a parameter for the authority to assign to my replicated uproperty. That is to say, my class looks something like this:
UPROPERTY(BlueprintReadOnly, Replicated)
AActor* SelectedTarget;UFUNCTION(BlueprintCallable, Server, Reliable)
void SetSelectedTarget(const AActor* _target);
The issue I come across here is, I get compiler errors that I can’t assign a const to a non-const. Though since I cannot pass the _target as a non-const, because blueprints interpret them as output if they are not const, which causes another issue, then the only solution I can find is to ‘cast away’ the const by using const_cast like so:
SelectedTarget = const_cast<AActor*>(_target);
However, this (from research) is very much frowned upon in the C++ world. This does work, but it doesn’t seem ideal.
Am I missing a trick, or vital understanding of the process here? Or is this really the only way to properly achieve this? Any info would be humbly appreciated. Thanks.