Hello!
I have a c++ class for a ceiling light. It has a Static Mesh, and a point light, where the Static Mesh is the root component.
The problem is that when spawned into the editor, the light component is in the complete wrong location.
I can fix this by adding a set location in BeginPlay, but that makes it impossible to edit the scene because it’s lit incorrectly ![]()
Even wierder, when i edit my blueprint child of the light, the blueprint viewport shows the light in the correct location, yet when i spawn it in, the component is in the wrong location!
Here’s my class, what can i do?
HEADER:
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "GameFramework/Actor.h"
#include "FacilityLightCPP.generated.h"
UCLASS()
class RSGAME_API AFacilityLightCPP : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AFacilityLightCPP();
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Mesh)
UStaticMeshComponent* LampMesh;
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Lighting)
UPointLightComponent* Light1;
/*UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Lighting)
UPointLightComponent* Light2;*/
};
SOURCE:
// Fill out your copyright notice in the Description page of Project Settings.
#include "RSGame.h"
#include "FacilityLightCPP.h"
// Sets default values
AFacilityLightCPP::AFacilityLightCPP()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
LampMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("LampMesh"));
Light1 = CreateDefaultSubobject<UPointLightComponent>(TEXT("Light1"));
Light1->SetRelativeLocation(FVector(0, 0, 0));
//Light2 = CreateDefaultSubobject<UPointLightComponent>(TEXT("Light2"));
Light1->SetRelativeLocation(FVector(0, 0, 0));
}
// Called when the game starts or when spawned
void AFacilityLightCPP::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AFacilityLightCPP::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
}


