C++ and Blueprints (LightSwitchBoth example)
- C++ classes can be extended with Blueprints ... programmers set up new gameplay classes in code that can be built upon and changed with Blueprints by level designers.
- Without specifiers, components, variables and functions in the C++ class would not be accessible to Blueprint graphs.
BlueprintableUCLASS specifier is inherited (AActor is Blueprintable).- Components
UPROPERTY(VisibleAnywhere, BlueprintReadOnly);DesiredIntensityUPROPERTY(EditAnywhere, BlueprintReadWrite);OnOverlapBeginUFUNCTION(BlueprintNativeEvent)withOnOverlapBegin_Implementation. If the Blueprint event does not exist, the C++ implementation executes instead. - In the constructor:
CreateDefaultSubobject<UPointLightComponent>(...),Sphere1->OnComponentBeginOverlap.AddDynamic(this, &ALightSwitchBoth::OnOverlapBegin); - Native components show dark blue icons in the Blueprint Components tab; Blueprint-added ones light blue.
- Construction Script executes when the Actor is moved within the level and when exposed variables change; the C++ constructor alone would not.
- EditAnywhere means each instance can have its own value.
- First code class in blank project: close editor, compile in IDE, reopen; build configuration must match editor executable. Existing projects: Hot Reload.