Gah - a solution with more questions. – EntropicLqd

UE3 talk:Actor native functions (UT3)

From Unreal Wiki, The Unreal Engine Documentation Site
Revision as of 05:52, 30 May 2008 by Wormbo (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

After talking to a trusted colleague about UnrealScript's use of out variables and why Java doesn't support them. He tells me its a bad idea because "Generally speaking out parameters are a form of pass by reference which essentially creates methods with multiple return types. There is some additional security but risks of spin-off effects exist. A preferred programming structure is to encapsulate the return types and the out variables into a new composite object."

I see some common sense in this, while working with Java, as it is slightly easier to just make a seperate private class and return that if there are multiple return types needed. With UnrealScript, I love the ability to simply create structures to do the same.

I don't neccesarilly agree with it in terms of UnrealScript though, most because I've been working for a long time and have grown acustom to it. But if what he says is slightly true, then there must be a reason why UnrealScript uses out variables Specifically for the Trace function where rather than the Hit object being returned, a HitCollision object would be returned that would hold a reference to the actual actor as well as HitLocation (or HitComponent with UT3?) etc...

The purpose for this may be memory usage and optimization but I would like input on this as its interesting to see why they would keep out variables eversince UE1. -DalinSeivewright 16:26, 28 May 2008 (UTC)

In UE1/2 out parameters were not really "call by reference", but actually "call by value and copy back after return". In other words, it was actually more expensive than pure input parameters. (AFAIK it's really call by reference in UE3 now.) The idea of the out parameters of the Trace() function are really that the function has not only its primary return value "What was hit?", but also "Where was it hit?" and "How was it hit?". If you really want additional info, you can pass the function a TraceHitInfo variable as the second-to-last parameter to get the additional data. -Wormbo 11:52, 30 May 2008 (UTC)