Hi everyone,
I am new to Unreal, with experience in C++. In this project, I am creating a weapon system that I can create multiple weapons out of a base blueprint, select different firing mechanics (e.g. pistol - one click one shot, machine gun - click and hold to shoot multiple bullets, etc).
This is how my base weapon looks like in blue print editor.
This is how RangeMechanic looks like in c++.
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class PROJECT_API URangeMechanic : public UActorComponent
{
GENERATED_BODY()
public:
UPROPERTY( EditAnywhere, BlueprintReadWrite, meta = ( Category = "Default", OverrideNativeName = "Firing Mechanic" ) )
TSubclassOf<UFiringMechanic> m_firingMechanic;
// Sets default values for this component's properties
URangeMechanic();
protected:
// Called when the game starts
virtual void BeginPlay() override;
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
UFUNCTION( BlueprintCallable, Category = "Weapon Functions" )
virtual void UseWeapon() { UE_LOG( LogTemp, Warning, TEXT( "WII : URangeMechanic::UseWeapon" ) ); }
};
In another blueprint, I added this to allow me to trigger UseWeapon() in RangeMechanic.
As expected, when left mouse button is click during play, the following is printed
LogTemp:Warning: WII : URangeMechanic::UseWeapon
As shown above in RangeMechanic code, I have another c++ class, FiringMechanic, that is supposed to be a base class to be inherited and have it’s UseWeapon() overrided.
My ideal would be to have UseWeapon() in FiringMechanic, have RangeMechanic reference call that function in FiringMechanic reference. In c++, it can be done as follows.
void URangeMechanic::UseWeapon()
{
UFiringMechanic* fm = m_firingMechanic->GetDefaultObject<UFiringMechanic>();
fm->UseWeapon();
}
I prefer to have UseWeapon() in FiringMechanic and classes that inherit from it, so to do that I need to access FiringMechanic reference via RangeMechanic reference in blueprint.
So here is the question, how do I access FiringMechanic reference via RangeMechanic reference in blueprint? I can’t seem to be able to get that reference.