How to Expose Variables Of an Instanced C++ Actor Component
Dear Polytopey,
I wrote my own C++ AI navigation system from scratch which uses actor components to store nav data.
I routinely place actors into the world and then edit the values of the component, on a per-instance basis, to have per-instanced nav-generation control.
So just to be clear, I am indeed talking about dragging actors that have your custom component, from C++, into the level and then editing the component’s values per-instance.
mentions the solution I am showing below, where you use a C++ base class for your actor, which houses your custom component.
If you don’t mind using a C++ Base class, an AActor-deriving class that stores your custom actor component, then the code I show below will great for you!
I encountered the issue of using C++ components with BP Actor classes while working on a custom component for Solus, and I am pretty sure you really do need a C++ AActor base class to store the component.
I found per-instance variable control to be essential for my own workflow, you might consider just making the necessary AActor-deriving C++ base classes to support the ultimate speedy workflow that your level designers and you will want in the Editor
**C++ Code**
Here's my relevant C++ code!
The C++ Actor Class that uses the component
UPROPERTY(VisibleAnywhere, Category=JoySMAHighest,meta=(ExposeFunctionCategories="JoyNav", AllowPrivateAccess = "true"))
UJoyNavComp* JoyNavComp;
_
**The C++ Component**
```
//Choosing a class group and making it BlueprintSpawnableComponent
UCLASS(ClassGroup=JoyMech, meta=(BlueprintSpawnableComponent))
class UJoyNavComp : public UActorComponent
{
GENERATED_BODY()
public:
UJoyNavComp(const FObjectInitializer& ObjectInitializer);
//UPROPERTY(EditAnywhere, BlueprintReadWrite,Category="JoyNav")
//FString CustomNavGroup;
/** Density Core Value, the smaller the more dense, density = 360/JoyNavDensity */
UPROPERTY(EditAnywhere, BlueprintReadWrite,Category="JoyNav")
float JoyNavDensity;
/** Draw Units! */
UPROPERTY(EditAnywhere, BlueprintReadWrite,Category="JoyNav")
bool DoDrawUnits;
UPROPERTY(EditAnywhere, BlueprintReadWrite,Category="JoyNav")
bool DoDrawJoyNavDisplayInfo;
/** Each radius gets its own layers of units! */
UPROPERTY(EditAnywhere, BlueprintReadWrite,Category="JoyNav")
TArray<int32> RadiusLevels;
/** Trim out units that are closer than Radius * TrimPercent */
UPROPERTY(EditAnywhere, BlueprintReadWrite,Category="JoyNav")
float TrimPercent;
//.. etc
```
With this setup I can load the editor, make a BP of my C++ actor that uses the component, and then drag it into the world, and edit the component values directly, per-instance.
I can even add to the dynamic array on a per-instance basis, it’s really neat!
Thanks Epic!
**Picture**
Notice the C++ variable names above of the component match what I can edit per instance in the level!
![16b5973d284e272195a1c0ed026f1b1c98d6facb.jpeg|1192x684](upload://3eTyLHbITjwk8gw16r4I9tZsBnl.jpeg)
Enjoy!
Rama