Download

Correct / Proper way to handle multiple weapons and to switch between them

Hi guys…

Context : I’m messing around, and working towards a FPS (think Unreal Tournament or Battlefield)

I have a WeaponBase class.
I define a struct


USTRUCT(BlueprintType)
struct FWeaponData : public FTableRowBase {

    GENERATED_USTRUCT_BODY()

    UPROPERTY(EditAnywhere)
    class USkeletalMesh* WeaponMesh;

    UPROPERTY(EditAnywhere)
    FString WeaponName;

};

Then I define these variables in the same class


    class USkeletalMeshComponent* MeshComp;

    UPROPERTY(EditAnywhere)
    class UDataTable* WeaponDataTable;

I then have a DataTable setup in the engine

on my BP_WeaponBase I set the Weapon Data Table to the above Weapon Data.

(Everyone with me still?)

Then on my Character class, I have the following setup:


class AWeaponBase* Weapon;

    UFUNCTION(BlueprintCallable)
    void SwitchWeapon(TSubclassOf<class AWeaponBase> WeaponClass);

So the question is:
Is this right way to do things? Or the preferred way? Or should there be a better tutorial I should be looking at?