How can I get components declared in C++ to show up in components tab in BP editor?

Let’s say I declare a camera component in my C++ code. How do I get it to show up in the components tab in the BP editor? I tried declaring it as such:

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = “Camera”)
TSubobjectPtr PlayerCameraComponent;

but it only shows up in the Defaults tab and I can’t move it around. I’m pretty confused about TSubobjectPtr so maybe that’s the issue. I tried making the UPROPERTY be just EditAnywhere but apparently I get a compile error when I use it with a TSubobjectPtr.

You should declare your camera subobject like this:

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Camera") TSubobjectPtr<class MyCameraClass> PlayerCameraComponent;

And if you are using your own camera class(not UCameraComponent) then add something like this before the declaration of you camera class:

UCLASS(config = Game, BlueprintType, HideCategories = Trigger, meta=(BlueprintSpawnableComponent))
class UMyCameraComponent : public UCameraComponent
{
	GENERATED_UCLASS_BODY()

        //Your code here
};

Hope this helps. :slight_smile:

I just tried it, doesn’t work. Getting really frustrated with the engine. I did a test where I made a brand new blueprint, and with the new one, it DID work and I DO see my stuff showing up in the components list. But that’s not terribly useful…will I have to re-create my blueprint every single time I add a new variable to the C++ code? Why don’t the changes in the C++ code show up in the blueprint I already made that derives from that class? Why do I have to make a new one to see anything happen?

I have experienced many similar problems with C++ components not being added or removed from editor blueprints. Not only that, but I have seen some posts on here from others with the same issue. Hopefully it can get tracked and resolved soon as it seems to be happening to a lot of people… and it really slows development… and it’s very irritating.

After declering subobject in header file you do this in constructor of class:

PlayerCameraComponent = PCIP.CreateDefaultSubobject<UCameraComponent>(this, TEXT("Camera"));
//set up settings, you need to set one or else you will get error
PlayerCameraComponent->SetRelativeLocation(FVector(100, 0, 0);
////
RootComponent = PlayerCameraComponent;

Now this will make component a root component, if you already have root component you need to use this insted of last line:

AddComponent(FName("Camera"), false, FTransform(), NULL);

In FName you use same name you used in first line

As AnXgotta already mentioned, it seems to be a bug and some people have it.
Workaround: Try recreating your blueprint which inherits from your class and everything should be fine

I filled a bug report New components are added to "Defaults" instead of "Components" - Programming & Scripting - Unreal Engine Forums referencing your question. Hope it gets fixed soon…

You can also try using the compile button in the editor. :slight_smile: I’ve met a person who had the same problem and resolved it by compiling in editor. :slight_smile:

Ya I do that, doesn’t work for me sadly.

Everyone needs to go to this bug report and up vote it!

This seems to be a confirmed bug that has a fix in the master branch, according to here:

I haven’t yet tried it but at least it’s under active development.

Got it from 's solus c++ tutorial, sound like what you’re looking for

#include "Components/ActorComponent.h"
#include "YourClass.h"

UCLASS(ClassGroup = Group, meta = (BlueprintSpawnableComponent))
class OVERFLOW_API UOF_PawnComponent : public UActorComponent
{
	GENERATED_UCLASS_BODY()

	
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Stuff)
		float Whatever;
}

it makes a new entry for “YourClass” in a group called “Group” in the component tab

oups sorry for bumping an old post with such a creepy answer x),I cannot find how to edit it however…

As of 4.19.2 this is still an issue. I created my BP when the UPROPERTY settings were wrong. Then I closed the editor, fixed the UPROPERTY settings and recompiled. But unfortunately the BP’s already created were still broken. However, any new BP’s I create work properly in the editor. So there must be some issue where the BP does not refresh on its own.