C++ TObjectPtr<> as a return type, is it good practice?

This makes a lot of sense, thank you to all that replied. I had the same suspicion regarding using it as a return type but wanted to confirm. Seems like TObjectPtr<> should be reserved for class or object properties in which you need to ensure the pointer ref is registered with the GC and made nullptr when owner is destroyed (correct me if I’m wrong on this), as suggested by @KaidoomDev 's reply to my question.

For now, I’ll leave my functions set as:

AActor* foo()

rather than:

TObjectPtr<AActor> foo() (what I was confused if I should change or not)

Thanks!

[Marking this as solution as a summary, thanks all that replied]

1 Like