I read all other questions but none are the same. How to call Blueprint function from C++ (when Blueprint inherited from other C++ class).
- RangedWeapon inherits of Tool
- Other Weapon(Blueprint) inherits of RangedWeapon
- From PlayerController I wanto to get the EquippedTool of Character and call a Method of Blueprint.
- Currently in the last code, “tool” is always NULL, after cast.
RangedWeapon.h
UFUNCTION(BlueprintNativeEvent, BlueprintCallable)
void Shoot();
RangedWeapon.cpp
void ARangedWeapon::Shoot_Implementation() {
UE_LOG(LogTemp, Log, TEXT("Shoot"));
}
Character.h
/** Tool Equipped */
UPROPERTY(EditAnywhere, Category = equipment, meta = (AllowPrivateAccess = "true"))
TSubclassOf<class ATool> EquippedTool;
PlayerController.cpp
void ASurvivormanPlayerController::Action() {
ASurvivormanCharacter* currentChar = Cast<ASurvivormanCharacter>(GetPawn());
ARangedWeapon* tool = Cast<ARangedWeapon>(currentChar->EquippedTool); //ClassDefaultObject, staticclass
UE_LOG(LogTemp, Log, TEXT("exists: %s"), (tool != NULL ? TEXT("True") : TEXT("False")) );
if (tool)
{
tool->Shoot();
}
}