Announcement

Collapse
No announcement yet.

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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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

    Code:
    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

    Code:
        class USkeletalMeshComponent* MeshComp;
    
        UPROPERTY(EditAnywhere)
        class UDataTable* WeaponDataTable;
    I then have a DataTable setup in the engine

    Click image for larger version  Name:	DT.PNG Views:	0 Size:	65.8 KB ID:	1752140

    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:

    Code:
    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?
    Last edited by MoZaHo; 04-28-2020, 01:39 PM.
Working...
X