Custom components with components

Hello! I was curious if it was possible to have a custom C++ component with components inside the custom component like this.

UCLASS()
class UForcingComponent : public URadialForceComponent
{
	GENERATED_UCLASS_BODY()

	/** The radius to apply the force or impulse in */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=ForceParticle)
	UParticleSystemComponent *ForceParticle;
}

And be able to make the particle attach to the root of this component?

Hello,

Please note, that Actor Component and classes, derived from it don’t provide Root Component field as Actor class and its children classes do. This is quite reasonable, since Components are designed to be used as sub-objects within Actors.

Thus, in this situation it will be more convenient to create a separate Actor for Force functionality and declare a field of this type inside other Actor.

If you like to learn more about the way Components work in Unreal Engine 4, you can find an informative guide here:

Hope this helped! Good luck!

1 Like