# whats the right way to inherit a USTRUCT?

**URL:** <https://forums.unrealengine.com/t/whats-the-right-way-to-inherit-a-ustruct/387043>\
**Category:** Editor Scripting\
**Tags:** inheritance, ustruct, unreal-engine, question, Blueprint, CPP\
**Created:** [March 5, 2017, 10:31pm UTC](https://forums.unrealengine.com/t/whats-the-right-way-to-inherit-a-ustruct/387043 "2017-03-05T22:31:01Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgumley](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mgumley](https://forums.unrealengine.com/u/mgumley)\
**Post date:** [March 5, 2017, 10:31pm UTC](https://forums.unrealengine.com/t/whats-the-right-way-to-inherit-a-ustruct/387043/1 "2017-03-05T22:31:01Z")

</div>

I’m trying to inherit a FHitResult, so I can add some extra parameters to it. What I have here mostly works, but when I break the hit result in blueprints, only my two extra variables show, and I cannot see the parent’s variables. How can I fix this?

```
USTRUCT(BlueprintType)
struct Ftw_HitResult : public FHitResult {
	GENERATED_BODY()
		
	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "tw", Meta = (DisplayName = "Total trace time") )
	float total_trace_time;

	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "tw", Meta = (DisplayName = "Velocity") )
	float velocity;
};
```

---

<div class="post-metadata">

**Author:** ![mgumley](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mgumley](https://forums.unrealengine.com/u/mgumley)\
**Post date:** [March 6, 2017, 9:05am UTC](https://forums.unrealengine.com/t/whats-the-right-way-to-inherit-a-ustruct/387043/2 "2017-03-06T09:05:34Z")

</div>

Thank you for trying to help me scott. You are right, there is almost never a “need” for inheritance, it is a convenience tool. This is the first time I found a use for it but it was easy to work without it.

Your suggestion will not work at all with my setup because those variables don’t mean what they might appear to mean.

However, if this is not possible, it really should be a feature request. This was just my first day working with a USTRUCT, and I’m sure there will be bigger problems later without proper inheritance.

---

<div class="post-metadata">

**Author:** ![ScottSpadea](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/scottspadea/32/1194682_2.png) [@ScottSpadea](https://forums.unrealengine.com/u/ScottSpadea)\
**Post date:** [March 6, 2017, 10:33am UTC](https://forums.unrealengine.com/t/whats-the-right-way-to-inherit-a-ustruct/387043/3 "2017-03-06T10:33:43Z")

</div>

if inheritance is helpful for the datatype, you should probably use a UObject, since blueprint allows object and actor inheritance, but not UStruct inheritance.

for inherited UStructs that you want to use in blueprints, the best you can do is create a new struct which contains the parent struct as one of its members.

for custom hit trace logic, which works with various actors, you can call an interface function on the OtherActor, which can return those Velocity/Time values.

---

<div class="post-metadata">

**Author:** ![mgumley](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mgumley](https://forums.unrealengine.com/u/mgumley)\
**Post date:** [March 6, 2017, 5:15pm UTC](https://forums.unrealengine.com/t/whats-the-right-way-to-inherit-a-ustruct/387043/4 "2017-03-06T17:15:36Z")

</div>

If this answer is correct then I will gladly give you an upvote. I would like someone to verify that USTRUCTS cannot be inherited. Is this documented somewhere?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_adaa72ab](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_adaa72ab](https://forums.unrealengine.com/u/anonymous_user_adaa72ab)\
**Post date:** [October 27, 2017, 9:36am UTC](https://forums.unrealengine.com/t/whats-the-right-way-to-inherit-a-ustruct/387043/5 "2017-10-27T09:36:38Z")

</div>

change the property from EditDefaultsOnly to EditAnywhere.

---

<div class="post-metadata">

**Author:** ![nande](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nande/32/1057698_2.png) [@nande](https://forums.unrealengine.com/u/nande)\
**Post date:** [January 4, 2025, 7:07am UTC](https://forums.unrealengine.com/t/whats-the-right-way-to-inherit-a-ustruct/387043/6 "2025-01-04T07:07:51Z")

</div>

> [@USTRUCT and inheritance](https://forums.unrealengine.com/t/ustruct-and-inheritance/142421):
>
> Hello, I found out something very strange. A USTRUCT can inherit a struct, only if it is a base struct. For instance the following snippet does not work: #pragma once #include "CoreMinimal.h" #include "FMinimumExample.generated.h" struct TEDIUM\_API FSubClassIntVector : public FIntVector { }; USTRUCT() struct TEDIUM\_API FMinimumExample : public FSubClassIntVector { GENERATED\_BODY() }; This gives compile error : ‘struct’: Can’t find struct ‘FSubClassIntVector’. At the same time, if yo…

it can work on certain conditions. i haven’t found how to do it on bp land though.

---

<div class="post-metadata">

**Author:** ![MagForceSeven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/magforceseven/32/906563_2.png) [@MagForceSeven](https://forums.unrealengine.com/u/MagForceSeven)\
**Post date:** [January 6, 2025, 4:17pm UTC](https://forums.unrealengine.com/t/whats-the-right-way-to-inherit-a-ustruct/387043/7 "2025-01-06T16:17:27Z")

</div>

> [@nande](#):
>
> i haven’t found how to do it on bp land though.

Depending on what you’re trying to do, you can use InstancedStructs which were introduced in 5.something and moved into the Engine in 5.5.

I say depending because you can get sort of the behavior of inheritance, but you still can’t do direct inheritence with blueprint structures. Like you can’t actually share members up and down the heirarchy. But you can get the behavior when passing around instances, cast to specific types and that sort of thing.

---

<div class="post-metadata">

**Author:** ![pelorustech](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pelorustech/32/594602_2.png) [@pelorustech](https://forums.unrealengine.com/u/pelorustech)\
**Post date:** [January 6, 2025, 5:14pm UTC](https://forums.unrealengine.com/t/whats-the-right-way-to-inherit-a-ustruct/387043/8 "2025-01-06T17:14:48Z")

</div>

To inherit a USTRUCT in Unreal Engine, use the GENERATED\_BODY() macro in the derived struct and ensure the base struct is marked with USTRUCT(). The derived struct can access and extend the base struct’s properties and functions. Avoid polymorphism, as USTRUCT doesn’t support virtual functions. Use composition for complex behaviors.

---

<div class="post-metadata">

**Author:** ![nande](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nande/32/1057698_2.png) [@nande](https://forums.unrealengine.com/u/nande)\
**Post date:** [January 6, 2025, 9:55pm UTC](https://forums.unrealengine.com/t/whats-the-right-way-to-inherit-a-ustruct/387043/9 "2025-01-06T21:55:32Z")

</div>

> [@pelorustech](#):
>
> Avoid polymorphism, as USTRUCT doesn’t support virtual functions. Use composition for complex behaviors.

i’ve implemented polymorphism with structs and virtual functions just fine. just don’t inherit from anything on the base struct.

---

<div class="post-metadata">

**Author:** ![stive322jack](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@stive322jack](https://forums.unrealengine.com/u/stive322jack)\
**Post date:** [January 7, 2025, 11:44am UTC](https://forums.unrealengine.com/t/whats-the-right-way-to-inherit-a-ustruct/387043/10 "2025-01-07T11:44:43Z")

</div>

In Unreal Engine, when you try to extend a structure like `FHitResult` by creating a custom struct or class in C++, the default behavior in Blueprints is that only the properties of your custom structure (like the extra variables you added) are shown, while the base structure’s properties may not be visible.

To ensure that both the parent structure (`FHitResult`) and your custom variables are visible in Blueprints, you need to do the following:

1. **Make sure the parent properties are exposed:** When you’re creating the custom struct or class in C++, you need to explicitly mark the properties from the parent class (`FHitResult`) as `BlueprintReadWrite`. This can be done using the `UPROPERTY` macro. By default, properties in `FHitResult` may not be exposed to Blueprints.For example, you would declare your custom struct as follows:

cpp

Copy code

```auto
USTRUCT(BlueprintType)
struct FMyCustomHitResult : public FHitResult
{
    GENERATED_BODY()

public:
    // Your extra variables
    UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Custom")
    float MyExtraFloat;

    UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Custom")
    FString MyExtraString;

    // Ensure that parent properties are accessible
    UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = "HitResult")
    FHitResult HitResult; // Or use the parent struct directly
};

```

1. **Ensure you’re using `BlueprintType` for inheritance:** The `USTRUCT(BlueprintType)` and `UPROPERTY` macros are crucial for exposing the properties to Blueprints. Make sure your struct is `BlueprintType` so that it can be inherited and used in Blueprints.
2. **Check the Blueprint Visibility:** After compiling your code, check the Blueprint editor. Your custom struct should now show both your added variables as well as the variables from the parent (`FHitResult`) structure. You may need to access `FHitResult` properties inside the custom struct manually or ensure you access the base class data properly in the Blueprint node.

### Additional Notes:

- If you have an array of `FHitResult` or an object that inherits from `FHitResult`, ensure that you use the correct Blueprint functions and correctly cast the parent struct when working inside the Blueprint logic.
- If you’re using `FHitResult` as a member in your custom struct (not inheriting from it), it should still be visible, but you need to make sure the `FHitResult` properties are marked `BlueprintReadWrite` (or `BlueprintReadOnly` if you don’t want them editable in Blueprint).
