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;
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.
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.
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?
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:
Shut off unreal
Completely delete the component
Build the project (full rebuild if you’re feeling saucy)
Run unreal and make sure the component is indeed gone
Shut off unreal, put component back, build project again.
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.
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.