Suppose I created two classes UActorComponent with names Class1 and Class2. In Class2 I wrote:
public: Class1* ClassInTheScene;
Next, I added these components to different actors. In editor Details, I want to select (assign) in component Class2 component Class1 from another actor, but there are only None. How to point to a component in the editor? Or is it better to do it differently? (It’s like in Unity you pass links to other game components on the scene.)
Not sure if this matters, I haven’t needed to use this in a while but did you make the actor component “blueprintable” and create a blueprint version of the C++ class?
UCLASS( ClassGroup=(Custom), Blueprintable, meta=(BlueprintSpawnableComponent) )
For UObject components, you will need to add “VisibleAnywhere” in the UPROPERTY().
It turns out that you can only point to the actor in the scene, but not to its component. Then the component of the actor can be obtained in the code through FindComponentByClass.
No, this is not something, as I understand it, this makes the parameter visible in the editor, but not editable.
Sadly as far as I can tell there is no way to directly set a pointer to a UActorComponent in another UActorComponent on the same Actor.
I use some workarounds to do this:
Make the value BlueprintReadWrite
Which will allow you to set it from Blueprints, and then set it on begin play in the actor blueprint
If there is only one component fo the type you want to link on the actor use
pointerToYourClass = GetOwner()->FindComponentByClass();
on begin play to set it from c++
If you have multiple of the same component but only want to link certain ones with certain other ones
use component tags to differentiate between them.
I think you might be looking for FComponentReference: FComponentReference | Unreal Engine Documentation
If you expose that with a UPROPERTY(EditAnywhere) (or whatever makes sense for you) then you should be able to setup these though the editor, or of course you can use C++ and set the ComponentProperty and OtherActor fields as required.