How to declare a property that accepts an actor layer reference?

I need to pass a layer reference to my ActorComponent script, I can pass a layer name but it’s a weak link so I want to pass a reference/pointer. I’ve tried this variant:

#pragma once

#include "CoreMinimal.h"
#include "Layers/Layer.h"
#include "Components/ActorComponent.h"
#include "PlanetGravityActorComponent.generated.h"


UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class JELLIANS_API UPlanetGravityActorComponent : public UActorComponent
{
    GENERATED_BODY()
    
public:
    UPROPERTY(EditAnywhere)
    float gravity = 10.0f;
    
    UPROPERTY(EditAnywhere)
    ULayer *layer;

public: 
    // Sets default values for this component's properties
    UPlanetGravityActorComponent();

protected:
    // Called when the game starts
    virtual void BeginPlay() override;

public: 
    // Called every frame
    virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

        
};

However, it doesn’t work: I still can’t drag my layer into the script property in editor.

How to declare it correctly?

P.S. I am a beginner in UE.

Given that little information, I have to make some assumptions. Do you have a Class based on ULayer, eg a Blueprint or something? Which you want to drag-and-drop into the property show as “Layer” for the ActorComponent?

Then use:

TSubclassOf<ULayer> layer;

This way you can drag-and-drop anything that is based on ULayer Class. Blueprints made of ULayer are child classes, a new class that inherite everything from ULayer.

1 Like