Greetings!
I’ve been working on some modification for the camera navigation and faced some strange (IMO) fact.
- Many setters have no checking:
...
UPROPERTY(config, meta=(UIMin = "1", UIMax = "8", ClampMin="1", ClampMax="8"))
int32 CameraSpeed;
...
...
void FLevelEditorViewportClient::SetCameraSpeedSetting(int32 SpeedSetting)
{
GetMutableDefault<ULevelEditorViewportSettings>()->CameraSpeed = SpeedSetting;
}
...
I would like to hear why it’s done that way?
I always used to think that setters have to check the values they set, except some cases (like heavy math or limited scope).
But since I’m working on Epic’s code (and hopefully would make a PR), I’m trying to write code “by the book”.
- Also, I would like to hear what would be the proper way to write similar functions:
int32 FEditorViewportClient::GetCameraSpeedSetting(int32 SpeedSetting)
int32 FEditorViewportClient::GetCameraFlightSpeedSetting(int32 FlightSpeedSetting)
or
int32 FEditorViewportClient::GetCameraSpeedSetting( int32 SpeedSetting, bool bFlightMode = false )
void FEditorViewportClient::FlightCameraAccelerate()
void FEditorViewportClient::FlightCameraDecelerate()
or
void FEditorViewportClient::FlightCameraApplyAcceleration( bool bSlowdown = false )
From the sources I could assume that code duplication is less critical than readability (means - two functions better than one).
- Last one, trickiest question. What is SCS? (SimpleConstructionScript?)
USimpleConstructionScript | Unreal Engine 5.2 Documentation
SSCSEditor | Unreal Engine 5.2 Documentation
(I’m asking since it also has camera navigation, at least in c++ sources)
The only description I found was:
And I just… “Huh?”