Same pointer is valid in BP but null in C++

The next uproperty component pointer:

UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
USkeletalMeshComponent* mesh;

constructor code:

mesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("mesh")); //succeeds all the time. checked.

Is returning a valid value in BP but null in C++.

Even calling a wrapper C++ ufunction brings the same effect:

UFUNCTION(BlueprintCallable, BlueprintPure)
UMeshComponent* getMesh(){return mesh;} 

When called in C++ it’s nullptr, but is valid in BP. The mesh exists and is seen in the world.

Important:

What is even more strange - is the fact that this behaviour occurs randomly with around 10% chance every play in PIE (without recompiling), while other 90% plays are completely fine both in BP and C++.

Where are you accessing that variable in C++ (what function)?

Are you sure you have tried to answer the right question? it has nothing to do with mine…

I’m accessing that on tick, without a network.

Hmm that is weird… i don’t really know what’s up with that…

Put breakpoint on it and do debug, breakpoint will be triggered by blueprint call too

Well, i’d say just put a null check in your C++ :confused:

there is a null-check already, but the point is that i have nothing to do with the null case because it’s completely illogical. the mesh exists in the world and i should be able to access it :[

@anonymous_user_f5a50610 I honestly can’t think of a way to debug this. the pointer is null for seemingly random reason

Could it be that you trying to return UMeshComponent instead of USkeletalMeshComponent without casting it first?

/** Get the mesh ./
UFUNCTION(BlueprintPure, Category = “Whatever”)
FORCEINLINE USkeletalMeshComponent
GetMesh() const { return mesh; }

It’s not necessary to cast child class to parent class in C++. a USkeletalMeshComponent inherits UMeshComponent so is a completely legal UMeshComponent variable.

I’ll try that when i get to coding, but it doesn’t look that it would work.

I will check that anyway and reply if it works, thank you.

Okay as expected, it does not work. Are you sure you did read the question?

I did read the question, but perhaps I didn’t understand it.

I created a new class and added the following to the header.

240162-1.png

I then added the rest in the cpp file.

Then I created the BP and added it to my level with the following BP in the actor.

Here’s the output.

240165-4.png

If I still don’t understand the question or this doesn’t work I apologize.

Thanks for the detailed answer, however my code for that works too, perhaps yout have missed the important note: “the fact that this behaviour occurs randomly with around 10% chance every play in PIE (without recompiling), while other 90% plays are completely fine both in BP and C++.”

No problem, I didn’t miss that either (it’s just a weird thing that’s happening). Could you post your code like I did above so I can see if you missed anything?

Sorry for the delay.

My code is unfortunately 3000 lines of code and the calling sequences are too long to post them all.

All the relevant code is pretty much there in the question. it seems like a very nasty bug :[

It’s kinda hard to debug code without seeing any. Could you post the code on pastebin?

I understand you. Can’t do post the entire code though, as it’s too private.

Anyway thank you for your help, i guess i will have to try harder on myself