---
title: C++ and Blueprints (LightSwitchBoth example)
source: https://dev.epicgames.com/documentation/en-us/unreal-engine/cpp-and-blueprints-example
version: Unreal Engine 5.8 Documentation
fetched: 2026-10-11
note: 原文摘录（英文），供 wiki 引用；非全文
---

# 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.
- `Blueprintable` UCLASS specifier is inherited (AActor is Blueprintable).
- Components `UPROPERTY(VisibleAnywhere, BlueprintReadOnly)`; `DesiredIntensity` `UPROPERTY(EditAnywhere, BlueprintReadWrite)`; `OnOverlapBegin` `UFUNCTION(BlueprintNativeEvent)` with `OnOverlapBegin_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.
