Download

changing values of parent struct in child struct

Hello,
I been having trouble as I have been moving blueprint DataTables over to c++ for project I plan to release soon as opensource project.
but what I trying to accomplish is set the default values of my padding for my Section Padding to 80.0 for example rather then using the default value of parent struct of using float 0.0.

below is my blueprint version:

as I trying to set the same values in my c++ version of the same idea as I have been porting my code over to c++

below is the example to my parent struct for the padding.

/** Simple struct for closing credits padding margin. */
USTRUCT(BlueprintType)
struct CREDITS_API FCreditsPaddingMargin
{
    GENERATED_USTRUCT_BODY()

        //float FCreditsUtilitiesPadding::Left = 1.0;
public:

    FCreditsPaddingMargin()
        : Left(0.0f)
        , Top(0.0f)
        , Right(0.0f)
        , Bottom(0.0f)
    {}

    /** reference to the left margin. */
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Credits, meta = (DisplayName = "Left Padding"))
    float Left;

    /** reference to the top margin. */
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Credits, meta = (DisplayName = "Top Padding"))
    float Top;

    /** reference to the right margin. */
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Credits, meta = (DisplayName = "Right Padding"))
    float Right;

    /** reference to the bottom margin. */
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Credits, meta = (DisplayName = "Bottom Padding"))
    float Bottom;
};

and my child function below where I call the above struct within another struct for my DataTable

/** Simple struct for closing credits section defaults. */
USTRUCT(BlueprintType)
struct CREDITS_API FCreditsSectionDefaults
{
    GENERATED_USTRUCT_BODY()

public:

    FCreditsSectionDefaults()
        : Title()
        , TitlePosition(ECreditsStartingPosition::Top)
        , SectionPadding() // @TODO Set Section Padding Bottom 80.0, (Left:0.0, Top:0.0, Right:0.0, Bottom:80.0)
    {}

    /** reference to the credits text object. */
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Credits, meta = (DisplayName = "Title"))
    FCreditsTextObject Title;

    /** reference to the credits starting position. */
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Credits, meta = (DisplayName = "Title Position"))
    ECreditsStartingPosition TitlePosition;

    /** reference to the credits padding margin. */
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Credits, meta = (DisplayName = "Section Padding"))
    FCreditsPaddingMargin SectionPadding;
};

how can I set the default value for the FCreditsPaddingMargin SectionPadding variable to change the default value for the float Bottom from FCreditsPaddingMargin struct to use 80.0 just like my blueprint version without changing the master values of the parent float values for just this section.

if you need to look at the full source you can view the file on my github here: https://github.com/dazzlesoftware/Norse/blob/master/Plugins/Credits/Source/Credits/Public/CreditsManager.h

as I looking for advise on how I can attempt this so I can do this for all my child structs as I still learning at porting blueprints over to c++ as I still learning how the engine works.

thanks for reading my post.

Stephen

You can declare in Cpp multiple overloaded Constructors, then use whatever version you need:



// defa
FCreditsPaddingMargin()
        : Left(0.0f)
        , Top(0.0f)
        , Right(0.0f)
        , Bottom(0.0f)
{}

You can declare in Cpp multiple overloaded Constructors, then use whatever version you need:



// default constructor 
FCreditsPaddingMargin()
: Left(0.0f)
, Top(0.0f)
, Right(0.0f)
, Bottom(0.0f)
{}

// another constructor 
FCreditsPaddingMargin( float x, float y, float w, float h) 
{
    Left = x;
    Top = h;
    Right = w;
    Bottom = y;
}




FCreditsSectionDefaults()
        : Title()
        , TitlePosition(ECreditsStartingPosition::Top)
        , SectionPadding(0.f, 0.f, 0.f, 80.f)
{}


thanks working great now. just what I was looking for. I will credit you for the tip in my source file :slight_smile: