What is the best practice for storing a reference to a component belonging to another actor?

What is the best practice for referencing a component to another actor?

I am storing references to components that belong to other actors within certain actors. I am wondering what the suggested way to implement this, in terms of both member declaration and definition.

For example in my custom actor class, I can declare this reference in different ways:

USomeComponent* otherActorsComponent;

or

UPROPERTY(Transient)
USomeComponent* otherActorsComponent;

And I can assign an initial value to this pointer like:

void BeginPlay() {
   // .....
    otherActorsComponent = otherActor->FindComponentByClass<USomeComponent>();
}

I ask because I’m having frequent issues of what appears to be the garbage collector causing sporadic crashes on Start, during, and at Stop of PIE. I’m not having issues that directly implicate any of these references, but I’m wondering if I’m messing up my GC object hierarchy somehow.

Automatic Updating of References

An Object reference stored in a raw
pointer will be unknown to the Unreal
Engine, and will not be automatically
nulled, nor will it prevent garbage
collection. Note this does not mean
that all UObject* variables must be
UProperties. If you want an Object
pointer that is not a UProperty,
consider using TWeakObjectPtr.

Garbage Collection

One practical implication here is that
you typically need to maintain a
UPROPERTY reference to any Object you
wish to keep alive, or store a pointer
to it in a TArray or other Unreal
Engine container class.

As a rule of thumb: use UPROPERTY macro when you are using Actor or component references as a member variable.