Hi, i have a problem where i make a movement component in the constructor of a pawn, it gets saved in the class but at begin play it is null. after looking into this issue i found that it might be an unreal bug. One solution i found was to delete the blueprint that was created from my code. This worked for me on my device but when other people try it on their device it is still broken. Is there a way to fix this without everyone im working with having to re create the blueprint?
#Component turns null after construction
1 messages · Page 1 of 1 (latest)
How are you storing the pointer to the component?
What are the specifiers in the header?
Usually stuff like this is because the pointer to the component is allowed to be edited and is then accidentally serialised as nullptr.
protected:
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Custom|Components")
TObjectPtr<UFloatingPawnMovement> _movementComponent;
this is how i store it in the header
For subobjects the correct UPROP is:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
TObjecPtr<UComp> TheComp = nullptr;
VisibleAnywhere is correct but BP-RW could be problematic
also post creation code
The pointer should never be edited outside the ctor
ill try changing that
It won't repair any BP:s that have already been broken.
But it will keep them from breaking in the future
but yeah also this
_movementComponent = CreateDefaultSubobject<UFloatingPawnMovement>(TEXT("Movement"));
this is how i construct it
also, i hope you launch editor from IDE and not try to bruteforce things with live coding
correct, although you don't need the TEXT macro
i am launching from my ide
alright, thanks for the help, i will try the things you suggested
When stuff like this happens I usually cut my losses and rename the component in C++.
don't see anything wrong. other than that _ ticking me off. usually component name and property name should be same for sanity reasons.
easiest way to debug is set a breakpoint at the CreateDefaultSubobject, when hit set a data breakpoint for a property change at property address, then resume until data breakpoint hits