c++ – Creating a laser light in Unreal Engine

I am developing a simulation and need to create a laser light. I have a rectangular actor which serves as the laser unit housing. For the laser itself I am using a spotlight with a light function. The texture for the light function is as follows:enter image description here

I created a C++ script which I added as a component to the rectangle. In the script I have a couple of UPROPERTY(EditAnywhere) variables, including one for the color of the laser and an AActor* for the spotlight. In the Editor I dragged the spotlight into the AActor slot.

In the BeginPlay() function I tried the following to set the color of the laser:

if (LaserLightActor)
{
    USpotLightComponent* SpotLight = Cast<USpotLightComponent>(LaserLightActor);
    if (SpotLight)
    {
        LaserLight->SetLightColor(LaserColor);
    }
    else
    {
        UE_LOG(LogTemp, Warning, TEXT("NO SPOT LIGHT FOUND"));
    }
}

But it says “No spot light found”. How can I get the spotlight actor in code to be able to set the light color?

Read more here: Source link