C++ Reference to an Actor in the Scene

I’m trying to make an C++ ActorComponent which implements a simple teleported logic, to learn more about the specifics of Unreal Engine (I’ve got experience in proprietary engines and Unity)

Upon overlapping with the UPrimitiveComponent on the Actor that has this TeleporterComponent, any other Actors would be teleported to the position/rotation of an Actor representing the teleportation arrival point, setup and picked by a LevelDesigner in the scene.

The overlapping is covered by the "Class Creation - C++ Only " doc, but establishing the link to the end point of the teleported has proven to be tricky.

I’ve tried doing this with a FComponentReference (since it apparently, allows to just get the Actor if no component is specified), but the Editor UI doesn’t allow me to pick an actor from the scene, and drag-n-dropping one on the field result in a red border appearing around it.

What would be the best way to achieve this?

Thanks in advance.

I think you over complicating things, UE4 is not as component centric as Unity. Your actor is a class on it own and it self contains the code and should have perticical function and role, components in UE4 are more like a add-on that you can add to actor, like mesh render, sound player, primery things that defines physicallity of the actor rether then function if you look on components, but in deed you can extra add function via components too.

Considering you want to make teleporter, i don’t think you will make few versions of teleporters and even if you can always reuse the code just by class inherence by making actors based of your teleporter actor just with extra components change it’s appereance (note that Blueprint is also a class same as C++ class). By making simple teleprotation actor it should be easier to operate and all you need to do is set target actor via simple pointer ,ATeleporter* for example or any actor (AActor*) can be target as all actors have location (if they have root component that have location), even if you make teleporter component using actor (AActor*) as a target is better solution.

Even if you make component you will probably end up making Teleporter actor sicne you need actor that contains your component in order to place it on the level, this is what happens with most components like UCameraComponent have ACameraActor ir UAudioComponent have AAmbientSound and all of them forward interface of component in to actor.

I have feeling you don’t know how actor classes work in UE4, watch my tutorial its about classes and objects that i made because in the past lot of people didn’t understood basics concepts of it, it not really targeting your issue but it shows how actor classes are reusable just by inherence without need of making components (in matter of fact in early versions of UE4 you could not make component classes in blueprints):


Thanks for the answer and I appreciate your time, but this doesn’t actually answer my original question.

I created an TeleporterActor and I still have the same issue: how do I reference an AActor from the scene as chosen by a Level Designer*.
I have tried an AActor* field and though it appears in the Details tab of the actor I cannot assign it by picking or drag’n’dropping

Do you know the proper syntax to achieve this?

It works for me, you should have combo slection and from there you have few selection option, either select from list of all actors on the level which oyu can name search, select currently selected actor or use sample icon (you know one that is usually used for picking sampling color in image editor) to pick actor from the viewport.

If you don’t see your target actor what are you want use as a target? since if it’s not on the list that means it’s not an actor or it is not on the map

Also forgot to mention alternative other option, you can make FVector with selection widget

UPROPERTY(EditAnywhere, Meta = (MakeEditWidget = true))
FVector TeleportTarget;

MakeEditWidget creates editable position selection widget on the map when you select actor, might be useful for you for something else too

Ok, I found where I screwed up: I thought EditXXXX of public property would have a default value that’d make them editable in windows, but it’s not the case. Adding EditAnywhere allowed me to point to an Actor in the scene.

Ok, I found where I screwed up, there is no need for Component Reference. AActor* can be used and in this way

AActor* Destination;

As a note: I thought EditXXXX of a public property would have a default value that’d make them editable in windows, but it’s not the case. Adding EditAnywhere allowed me to point to an Actor in the scene.