I am trying to write a function in an in-editor plugin that creates a point light. This is what i have:
.h
#pragma once
#include "GameFramework/Actor.h"
#include "vpCreate.generated.h"
UCLASS()
class AvpCreate : public AActor
{
GENERATED_BODY()
public:
UPROPERTY()
class UPointLightComponent* PointLight1;
AvpCreate(const FObjectInitializer& ObjectInitializer);
UFUNCTION()
static void MakePLight(FString PLightName, FVector location);
};
.cpp
#include "m2uPluginPrivatePCH.h"
#include "vpCreate.h"
AvpCreate::AvpCreate(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
PointLight1 = ObjectInitializer.CreateDefaultSubobject<UPointLightComponent>(this, "PointLight1");
}
void AvpCreate::MakePLight(FString PLightName, FVector location)
{
AvpCreate create;
UClass* ClassRef = create.PointLight1->GetClass();
FTransform ActorTransform = FTransform::Identity;
GEditor->AddActor(GEditor->GetEditorWorldContext().World()->GetCurrentLevel(), ClassRef, ActorTransform);
}
Is this the right way to call the constructor? ‘GetClass’ is wrong, what is the correct way to get the class of a light for the ‘AddActor’ function?
Since I am using regular lights, do i even need to create a custom class, or can I just use the existing editor PointLight Class somehow?
Thanks!