Get vs Direct




I’m coming from years of unreaIscript and prefer the top one, is there any pitfall I’m missing by writing it this way? I see a lot of people using the second style.

Probably just pure pleasure, always is a good idea have gets and sets, that property should be private and just accessible from a get method, but since UE cannot include UFUNCTIONS inside USTRUCT, probably that is why,

I’d like that epic treat ustruct like uclasses

The Actor in a FHitResult is a TWeakObjectPtr<class AActor> so it depends on what you should do with the Actor. In your simple case the “->” in the first example actually calls a Get() and returns back a real AActor* for you.

Best is maybe to browse through the Weak Pointers documentation to make sure.

Both are identical. Calling -> on a weak pointer accesses to stored pointer directly.

I imagine that at some point, Epic want to hide ‘Actor’ behind an accessor. Always good practice to use an accessor function if one is available.