CHADALAK1
(CHADALAK1)
November 20, 2014, 7:56am
1
Question I’ve been curious about for a long while is how would I expose C++ variables to Blueprint UMG? I want to be able to put a weapon splash art and ammo count. Only thing is I have no clue what to do to go about doing this.
Say if I have a struct in my weapon like this.
USTRUCT(BlueprintType)
struct FWeaponData
{
GENERATED_USTRUCT_BODY()
UPROPERTY(EditDefaultsOnly, Category = Ammo)
int32 MaxAmmo;
UPROPERTY(EditDefaultsOnly, Category = Config)
float TimeBetweenShots;
UPROPERTY(EditDefaultsOnly, Category = Ammo)
int32 ShotCost;
UPROPERTY(EditDefaultsOnly, Category = Config)
float WeaponRange;
UPROPERTY(EditDefaultsOnly, Category = Config)
float WeaponSpread;
UPROPERTY(EditDefaultsOnly, Category = Config)
FString Name;
UPROPERTY(EditDefaultsOnly, Category = Config)
TSubclassOf<UTexture2D> SplashArt;
};
And I want UMG to see them and display them in my Widget Blueprint. I’m actually very new to UMG. Very Familiar with Canvas, but I want to give UMG a try with this situation.
CHADALAK1
(CHADALAK1)
November 20, 2014, 9:19am
2
Actually answered my own question here. Didn’t realize I could break weapondata in it’s struct in blueprint as well. Result is this
USTRUCT(BlueprintType)
struct FWeaponData
{
GENERATED_USTRUCT_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Ammo)
int32 MaxAmmo;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Config)
float TimeBetweenShots;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Ammo)
int32 ShotCost;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Config)
float WeaponRange;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Config)
float WeaponSpread;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Config)
FString Name;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Config)
UTexture2D* SplashArt;
};
and made sure i added particular things in UPROPERTY when making the Weapon Config struct
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Config)
FWeaponData WeaponConfig;
and I was able to cast out the blueprint event like this
and it turned out like this
Horray!!!