Casting UStruct to derrived struct

You can’t use “normal” casts for UObjects. You need to use the Cast methods you were originally using.

You can either check for null after you do the Cast (to prevent accessing a failed cast), or do a IsChildOf check before the cast (which may be a bit redundant).




if (FMessageStructDerived* derivedStruct = Cast<FMessageStructDerived>(&myStruct))
{
   // Cast was successful, continue on.
}

// Same logic as above, but using IsChildOf
if (myStruct.IsChildOf<FMessageStructDerived>())
{
    FMessageStructDerived* derivedStruct = CastChecked<FMessageStructDerived>(&myStruct); // CastChecked will crash on a failed cast, but our IsChildOf guarantees that our cast will be safe.
}