How to get a component as a variable inside another component in the same Blueprint

So, I am trying create a new component from c++ which needs to get other components as variable in the same blueprint. I am writing this to get variable:

UPROPERTY(Category = "Tween", EditAnywhere, BlueprintReadWrite)
USceneComponent* sceneComponent;

This gives me child classes to select as variable. It would be great if you would help me to select the component itself.

You can check the list of UPROPERTY specifiers here: UM:: | Unreal Engine 5.5 Documentation | Epic Developer Community

In the list, there are a few that catch my eye as candidates to fix your problem: AllowedClasses (and possibly paired with ExactClass) and AllowEditInlineCustomization.

Also, I’m pretty sure that UE5 wants us to use TObjectPtr<> for UPROPERTIES and not raw pointers

To fix your issue and allow selecting the component directly in the Blueprint, you should use FComponentReference instead of a raw pointer. Replace your property with UPROPERTY(Category = "Tween", EditAnywhere, BlueprintReadWrite) FComponentReference SceneComponentRef;. This will let you select components directly from the dropdown in the Blueprint Editor without showing child classes. FComponentReference is specifically designed for referencing components within the same Blueprint and ensures safe serialization. Alternatively, you can use TObjectPtr<USceneComponent> if you’re using UE 5.1 or higher, which is a safer modern approach for UObject references.

1 Like

Thanks for the quick solution. I will be able to try it tomorrow and get back to you.

FComponentReference is working wonderful here. Thanks for the input. This has helped a lot :slight_smile: