Why the initialization list is never used in UE4?

I have seen from the examples in the markeplace that in Unreal Engine 4 to initialize class fields the initialization list is never used and the body of the constructor is used instead.
Why?

I cut a chunk of code from the Shooter example.

Why this:



AShooterWeapon::AShooterWeapon(const class FPostConstructInitializeProperties& PCIP) : Super(PCIP)
{
        ... other stuff I cut away...
	
        bLoopedMuzzleFX = false;
	bLoopedFireAnim = false;
}


Instead of this:



AShooterWeapon::AShooterWeapon(const class FPostConstructInitializeProperties& PCIP) : Super(PCIP), bLoopedMuzzleFX(false), bLoopedFireAnim (false)
{
        ... other stuff I cut away...
}


I have always used the initialization list in my UE4 code, should I stop doing that?

Hi Ivan,

It’s perfectly fine to use the initialization list. Earlier in UE4, there was special code in the constructors that worked differently when making the class default object than when making a regular constructed object, which is why most of the code for existing classes is in the constructor body. However, that code is no longer necessary and you can use the initializer lists now.

One thing to watch out for is that you should list items in the initializer list in the same order as you declared them in the header, or you will get a compile warning on every platform but Windows (unfortunately MSVC doesn’t have a warning for initialization order, while all Clang based platforms do).

Cheers,
Michael Noland

Clear answers! But it may be wise to don’t use initialization list in case of in a future this change…

You should be fine. Worst case you would need to move your code into the initialization member that they ask you to use, but that’s not likely to be a change they go back on.

We will not be making a change that would prevent use of the initializer list in the future, it is safe to rely on.

Cheers,
Michael Noland