Download

How to add an existing light to a custom C++ class?

Hey there,

How can I add an existing light from my scene to a custom C++ class?

If I create a default subobject in code, it creates a new light to that class. But I want to have this little eardropper symbol with which I can choose a light that is already inside my world.

So basically I did it like:

Sun.h


UPROPERTY(EditAnywhere)

UDirectionalLightComponent* Sun;

Sun.cpp


Sun = CreateDefaultSubobject<UDirectionalLightComponent>(TEXT("Sun"));

I created a blueprint from that class but like I said it creates a new light instead of letting me pick one that is already there.

Make it a pointer to a directional light “actor” and init to null. Then you will be able to choose in editor.

Guessing it would be this? https://docs.unrealengine.com/en-US/…ght/index.html

We have a volume in our code that allows level designer to point to a target actor. This is all that it requires:



// point to target actor in editor
UPROPERTY(EditInstanceOnly)
AInteractiveActor* _targetActor = nullptr;