Curious about UE object model and execution speed

So I’m learning C++, and curious about why some functions return pointers while others return copies. Before starting this course, I assumed functions returning anything other than simple types like float, chars, integers, etc., would return pointers to improve execution speed. So to get an actor, we get the pointer to it - that makes perfect sense to me. However, to get a transform form an actor, we get a copy of it - I figured this would be considered too expensive. What are the thoughts of you guys (and gals) who are in the know about this kind of stuff?

// GetOwner() returns a pointer, but then GetActorTransform() returns a copy
FTransform xform = GetOwner()->GetActorTransform();

-Paul

FTransform is just 10 floats (FQuat + 2x FVector) so probably within the realm of fine to return by value for most platforms. Though it has been recently changed to return by const reference.

Is it the member variables that determine how slow or how fast an object copy takes? FTransform like you say only has 3 variables (10 floats), and they of course are unique for each copy, even if their values are the same. FTransform also has over 80 member functions. Am I correct that there is less overhead with member functions as these aren’t really copied like variables are? This is something I’ve always wondered since I’ll need to be coding my own objects at some point, and want to keep things moving fast and cheap considering this is a game engine and all.

I may be digressing from the course content a bit. I’ll do my part and google this and get more info.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms