[BUG, Unsolved, Workaround.] UE 5.1 Constructor created component invalid on BeginPlay

Using the following setup the UActorComponent is always invalid on BeginPlay of the character. The component is correctly visible in the blueprint editor and there are no compilation errors c++ or BP side. What is this about? Any reason it would somehow be deleted by the engine?

protected:

	UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
		UPawnCameraManagerComponent* ACPawnCameraManager = nullptr;

ACharacterALS::ACharacterALS() {
	ACPawnCameraManager = CreateDefaultSubobject<UPawnCameraManagerComponent>(TEXT("PawnCameraManagerComponent"));
}

Related and unsolved:

Missing Components Created Through C++ Constructor - #5 by tailedmouse

When creating a SkeletalMeshComponent in Actor Constructor, why is it null in BeginPlay?

Component pointer invalid after creation in class constructor

How to create a custom UActorComponent properly?

Initialized components are null during gameplay

Actor component is null in BeginPlay, Tick

Bump. The exact same setup works for other components on the character (spring arm / timeline). The custom actor component overrides nothing.

Blueprint corruption apparently. Temporarily marked the UPROPERTY transient and recompiled the BP… Removing transient and it is null again.

  • Edit you’d think that after marking the property transient, that modifying + resaving the blueprint could fix this problem. It doesn’t.

I’m pretty sure there happened some corruption during the blueprints serialization.

To me this happened multiple times, always when having a Blueprint actor that inherits a C++ one. It is usually fixable by renaming the component variable in C++ (which might break references), run the editor, change something in the blueprint and save, close the engine, change the variables name back again, run the editor, change something in the blueprint and save. Most (or maybe all) of the time the broken component contained at least one multicast delegate.

Another option would be to delete the blueprint and recreate it from scratch…

Sadly I was never able to reproduce that issue to create a bug ticket. It happens randomly.

It’s a shame because I use Blueprints only to make variants of my c++ classes noto only for the benefits but so that no one can screw with the c++ logic. It appears they can simply through corruption. It’s almost impossible to manage that or even know one went corrupt in a big project because it is not detected as a corruption. I’ll try what you said, rename the property then rename it back.

My component does contain a single multicast delegate. I think the problem might be that the property used to be a private one and I remember altering it to a protected one + the flag BlueprintReadOnly to make the editor shut up :slight_smile: Blueprint does not keep track of that, it just fills with garbage.

Renaming the c++ property works. I am reporting this as a bug. I’ll post a tracker here when / if I get one, there are a million bugs on their issue tracker.

2 Likes

Were you able to create an issue for this in the end? It seems crazy to me how prevalent this problem is. I find that renaming the component variable does indeed fix the issue, but it’s usually only temporary. Also, if I try to change the variable name back, I get crashes again. It seems now that I have a specific name I can no longer use in my class :man_facepalming:

I’m working on a reasonably small project, but this must cost larger projects a considerable amount of lost time. It wouldn’t be so bad if you could guarantee that once fixed, it wasn’t going to reoccur, but this doesn’t seem to be the case.

Also, as pladux mentioned, this is currently the only class I’m using a Delegate in… which is interesting

I move this post to the bug report section, I recently saw an EPIC bot post a status update on one that the posts are actually being processed.

This bug happens for components, variables, methods, tons of stuff ends up in blueprints and will never be cleaned. Short while ago I came across this:

Exception when trying to bind a UFUNCTION with AddDynamic to a Delegate

Just wanted to say that this still happens in 5.3.2
I had this issue 3 times already on different projects, and In the last one I don’t have any delegates on the component.

Workaround works

1 Like