Custom component and existing blueprints

Hello,

Today I tried creating some custom components and ran intro a problem.
This is how the class looks like:

UCLASS(Blueprintable, meta = (BlueprintSpawnableComponent))
class TPS_API UTPSComponent_Shield : public USphereComponent
{
	GENERATED_BODY()
        // CODE
}

Nothing fancy really, no overriding or anything. Then I decided to add it to my character:

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Skill, meta = (AllowPrivateAccess = "true"))
	class UTPSComponent_Shield* ShieldComponent;

and create it inside the constructor like this:

ShieldComponent = CreateDefaultSubobject<UTPSComponent_Shield>(TEXT("Shield Component"));
	ShieldComponent->AttachTo(RootComponent);

In my game I have a blueprint that inherits from my character. Once I opened the blueprint I saw that my component is there but it was actually empty:

I found this thread on the forums that reported a similar issue:

I decided to try create a new blueprint that inherits from MyCharacter and see if it would work. Turns out, it solves the problems. Still it would be nice if this bug was fixed as recreating blueprints every time might be difficult and impractical.

It’s a pity these issues still exist with 4.8, component problems like this have been around for ages and make it a real pain to develop c++ and blueprints concurrently. Your problem is very similar to one of those linked here, which was apparently fixed for 4.8.

Sad to hear that indeed. I really like using both C++ and blueprints at the same time. C++ for the “heavy lifting”, bluperints to quickly prototype new ideas and easily change data. I hope that those issues will be fixed eventually.

Hey -

Can you explain in more detail how you’re setting up your character and sphere component? I created a new character class and new sphere component class. After creating a blueprint based on the character class I added a pointer reference to the new sphere component based on the code you provided. After compiling the code (triggering a hot reload) the ShiledComponent showed up in the blueprint’s Viewport and all of the properties in the details panel were editable except for the name which is expected since it is named in code.

Cheers

Hey ,

The setup was as described above. I created a component and wanted to add it to my existing Character class. I had a blueprint that inherited from that class. When I added the pointer to the component inside .h and .cpp files the BP would have a null component.

The problem is that I just tried to reproduce the issue on a new project and couldn’t do it.

  1. Started a new CPP TPS project.
  2. Deleted the default character BP and created my own
  3. Created my own Sphere Component class and added a pointer to it inside the Character .h and .cpp files.
  4. Everything worked fine even with the editor open.

Additionally I tried creating a Game Mode BP and setting it as default because I thought it might be related somehow but it wasn’t the case.

Sorry that I can’t help you further.

Hey -

Since you were able to work around this by creating a new blueprint and the issue cannot be reproduced in a new project would be possible for you to send me a copy of your project to investigate? If you can upload the project to dropbox you can send me a private message on the forums with a link to download if you would rather not post it publicly here.

Cheers

I am also having this problem. Made a CPP custom component, each time I am changing something a little major, the component in the BP is broken. I have been recreating fresh BP each time so far but now it is really becoming unmanageable. I can give you something reproducible through PM if necessary.

Hey Douglas-

If you have a sample project experiencing this issue then please send me a PM on the forums with a link to download it. Additionally, does the same behavior exists on a new project as well?

Hey -

I got the sample project you sent me on the forums and tested it out. After commenting out the lines that created the ShieldComponent in the TPSCharacter class and compiling the change I created a new blueprint based on the class and then uncommented and compiled again. When the ShieldComponent showed up on in the component list the options in the details panel were visible.

Hi ,

Thanks for testing this out. Were you able to get it working in the existing blueprint or did you have to create a new one? I know it works when you create a new BP based on the class but I don’t want to recreate my BPs each time I decide to add a component.

There is no TPSCharacter blueprint in the project by default. What I did test was commenting out the code that added the shield component to the character and compiled the code. I then created a blueprint from the TPSCharacter class which did not have a shield component on it. I uncommented the code to add the shield component and compiled again. When the compile finished the shield component was added to my TPSCharacter blueprint and was editable in the details panel. If I add the shield component to any of the bot blueprints available in the project then the details are also editable.

Thanks for the explanation. I will try this again.