Component add in C++, edit in Blueprint

I’ve got a class which derives from AActor, and I create it’s component structure in C++ (component pointers part of the class declaration, create the components in the class constructor). I then would like to be able to create blueprints from this class and modify the component states.

It mostly works fine, I can make blueprints based of my class, and the components successfully show up in the Blueprint component graph in the structure I defined. They don’t however allow me to edit the components themselves, as in, when I select the components I can’t edit any of the components’ default state in the blueprint.

Is there a way to make this work, or if I declare the components in C++ I’m stuck to modifying these components in C++?

Hi jPinhao,

You need to mark your component properties with the flag: VisibleAnywhere, like this:

UPROPERTY(VisibleAnywhere,Category=Character)
class UPaperFlipbookComponent* Sprite;

You probably need the flag BlueprintReadOnly too, so that you can access the property in the graph.

UPROPERTY(VisibleAnywhere,BlueprintReadOnly,Category=Character)
class UPaperFlipbookComponent* Sprite;

Cheers,

To edit, you’ll want BlueprintReadWrite

If you want to expose a function, you’ll want

UFUNCTION(BlueprintCallable)
void Foo();

You can find more information relating to UPROPERTY and UFUNCTION specifiers here: UPROPERTY || UFUNCTION

Just a note, BlueprintReadWrite will allow you to override the component in the blueprint graph. It might or might not be what you want. I encourage you to play with the UPROPERTY flags (especially these related to Blueprint*, Edit* and Visible*) that MJLaukala` linked to. Then you can get a feel for what flags that is needed in each case.

VisibleAnywhere was exactly what I needed, I can now modify the component settings. I think I had tried EditAnywhere before and that threw errors so it got me confused, it’s a bit odd but I guess components work slightly differently to other members :slight_smile:

This is exactly what I’ve been looking for. =) Should be marked as the correct answer.

Just one problem remains. How would one go about this with the RootComponent?

I found that by declaring a variable for holding the USceneComponent, which will be set as the RootComponent later on, and setting the specifiers there works. However this seems kind of redundant, since I now have two pointer for one and the same Component. Is there a better way?