component is being set to null after edit

Hello,
I’ve been dealing with this situation for almost a year and am close to giving up.

I have a c++ component, as declared as follows :





UCLASS(Blueprintable, ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class GAMEPROTOTYPE_API UConditionComponent : public UActorComponent


in a character class it is used as a member :





    UPROPERTY(Replicated, VisibleAnywhere, BlueprintReadOnly, Category = Custom)
    class UConditionComponent* ConditionnComponent;


and initialized in the constructor:





ConditionnComponent = CreateDefaultSubobject<UConditionComponent>(TEXT("ConditionComponent"));


everything works fine, until i change something in the component, at that point its being set to null after the constructor, thus not showing up in the details panel of the character.

i have many components declared like this one, and this situation recurs in all of them.

previously, i changed the name of the components, regenerated project files, changed it back and regenerated again - this solved the errors, but messed up my blueprint code, thus not an ideal solution.

please save me :eek:

If it’s a default subobject then I have no idea why you mark it as replicated.

​​​Anyway, that doesn’t explain much, your problem might come something within your code…

the replicated code was just to test something

what code can make something be null only when its class is changed and rebuilt?
it happens if i add a property in the component, change the name or the type of an existing property, or when adding a method.

Are you using Hot-reload while you change your Component’s header file?

used to, but now i close the editor when i do that

Something in your “generated” folder could be broken because of that, regenerating files and rebuilding is good practice.

when things go weird like that i always try to delete the folders, generate again and build but that didnt help here…
how do you suggest avoiding this?

BTW thank you for helping:)

I’ve had problems like this before, but it’s extremely rare. I hot-reload constantly and it only happened a few times in the last 4 years.

My solution:

  1. Shut off unreal
  2. Completely delete the component
  3. Build the project (full rebuild if you’re feeling saucy)
  4. Run unreal and make sure the component is indeed gone
  5. Shut off unreal, put component back, build project again.
  6. Re-open unreal, tadaa.

It seems like that specific component is cached or corrupt. However unreal works, you essentially need to remove it from the build and then re-add it fresh.

It may break your blueprints temporarily. You might be able to remedy this by loading into an empty map instead. I believe a blueprint is not on the map, unreal won’t check it and won’t notice it’s broken until you access it some way.

1 Like

Since this is the first google result, I’d like to add something.

I had the same problem, tried renaming, deleting pretty much everything in the project, reparenting blueprint, cloning blueprint, …

The only thing that eventually worked:

Remove the UPROPERTY from the variable.

2 Likes

My dude, don’t ask me for details but I fixed a similar problem just by naming the component different than the class of the component. Idk why when they have the same name Unreal modifies in memory component and it was null when I tried to access it. Just try ConditionnComponent = CreateDefaultSubobject<UConditionComponent>(TEXT("ConditionCmpt")); and that worked for me. =D

Thanks a ton buddy. This works!
Spent a s#it ton of time trying to fix the issue, nothing worked. Until this. Saying this is an understatement, but you are a godsend.