How to set an Actor pointer in Details panel that implements a specific interface?

An Actor pointer is declared in a class.

UPROPERTY(EditAnywhere)
AActor* TargetActor;

This targeted Actor is available in the Level and it implements a custom interface (IInteractions).
I’d like to set the pointer in Details Panel without listing all the Actors from Level (only Actors that implement that specific interface).

UPROPERTY pointers cannot be interfaces so the following code is not allowed:

UPROPERTY(EditAnywhere)
IInteractions* ITarget;

Also this snippet doesn’t work either:

UPROPERTY(EditAnywhere)
TScriptInterface<IInteractions> ITarget;

Is it possible implementing such a functionality?

2 Likes

I could have sworn that I used to be able to just use an interface property type, and the editor would properly populate my list of possible actors from the dropdown menu when I go to assign the value. However, this doesn’t seem to be working for me anymore. Maybe because I moved from UE 4.26 to UE 5.0.2, or maybe because I changed my interface type from defined in blueprint to defined in C++ code.

The only way I’ve figured out how to do this now is to make a custom Actor class that implements the interface, make a property that points to that actor class, and then make all my classes that want to implement the interface, also use that class as a parent.

This obviously isn’t scalable if I want to have any of these actors implement more than one interface.

I’m curious if anyone knows the right way to make the property editor window properly show all the actors that implement a specific interface.

UPROPERTY(EditAnywhere, meta = (AllowedClasses = MyInteractInterface"))
TArray<AActor*> ActorsToTrigger;

AllowedClasses meta specifier works for Interfaces as well!

2 Likes

Bro you’re a genius, I simply couldn’t find anything within Unreal source code to teach me that, you’re a life saver, it worked like a charm.