Download

Syntax Question, square brackets and structs

I was reading the source for [FONT=Courier New]UChildActorComponent::CreateChildActor() today and got a little confused. I’m re-learning C++ after many years away and came across some syntax that I didn’t understand and was hoping some kind soul would help. The following code confused me:



                FActorSpawnParameters Params;
                Params.[bNoCollisionFail](API\Runtime\Engine\Engine\FActorSpawnParameters\bNoCollisionFail) = true;
                Params.[bDeferConstruction](API\Runtime\Engine\Engine\FActorSpawnParameters\bDeferConstruction) = true; // We defer construction so that we set ParentComponentActor prior to component registration so they appear selected
                Params.[bAllowDuringConstructionScript](API\Runtime\Engine\Engine\FActorSpawnParameters\bAllowDuringConstructionScript) = true;
                Params.[OverrideLevel](API\Runtime\Engine\Engine\FActorSpawnParameters\OverrideLevel) = GetOwner()->GetLevel();
                Params.[Name](API\Runtime\Engine\Engine\FActorSpawnParameters\Name) = [ChildActorName](API\Runtime\Engine\Components\UChildActorComponent\ChildActorName);
                Params.[ObjectFlags](API\Runtime\Engine\Engine\FActorSpawnParameters\ObjectFlags) &= ~RF_Transactional;



FActorSpawnParameters is a struct. I’m confused by the dot followed by square brackets followed by parens. I’m assuming that these lines are populating the struct, but the syntax here is new to me.

Any help would be appreciated.

I believe it has to do with UE4’s reflection preprocessor, not standard C++ syntax. Not exactly sure what it does. I’m assuming it sets some globally accessible value based on the path within the parenthesis.

EDIT: I’m looking at the source code in GitHub and don’t see the same syntax that you posted, so it must be something to do with the preprocessor

Yeah, that’s not what the code actually looks like, where did you find this?

EDIT: That code was copy/pasted from the docs here, it’s a bug in the documentation generator, title is supposed to get turned into a link but obviously that didn’t happen in this case.

Ah, okay, that makes sense. Thanks for the info.