Component pointer reset to null after assigned. UPROPERTY doesnt fix.

Im trying to make an HTTPComponent attach to a floating pawn.

My header file for the pawn looks like this:

#include "InputActionValue.h"
#include "Player/FLCameraController.h"
#include "Vehicle/VehicleComp.h"
#include "Inventory/InventoryComp.h"
#include "Networking/HTTPComp.h"
#include "CoreMinimal.h"
#include "EnhancedInputComponent.h"
#include "GameFramework/Pawn.h"
#include "Blueprint/UserWidget.h"
#include "FLCameraPawn.generated.h"
public:
	// Sets default values for this pawn's properties
	AFLCameraPawn();
virtual void Tick(float DeltaSeconds) override;
	UPROPERTY(EditAnywhere,BlueprintReadOnly)
		APlayerController* AsPlayerController;
	UPROPERTY(EditAnywhere,BlueprintReadOnly)
		AFLCameraController* AsFLCameraController;
	UPROPERTY(EditAnywhere,BlueprintReadWrite)//important component. 
		UHTTPComp* HTTPCompVariable;

The cpp file for the pawn looks like this:

AFLCameraPawn::AFLCameraPawn()
{
	PrimaryActorTick.bCanEverTick = true;
	AActor::SetReplicateMovement(true);
	SetReplicates(true);
	bAlwaysRelevant = true;
	HTTPCompVariable = CreateDefaultSubobject<UHTTPComp>(TEXT("HTTPComp"));
}
void AFLCameraPawn::Tick(float DeltaSeconds)
{
	Super::Tick(DeltaSeconds);
	if(bDebugMode)
	{
		if(HTTPCompVariable)
		{
			GEngine->AddOnScreenDebugMessage(7, 0.1f, FColor::Red, FString::Printf(TEXT("Is replacement host: %s"),(HTTPCompVariable->bIsReplacementHost ? TEXT("true"):TEXT("false"))));
		}
	}
}

The HTTP has 2 functions and a simple boolean variable. Nothing worth showing here unless its detrimental to solving the problem.

The problem:
HTTPCompVariable returns invalid after creation in constructor. THIS TIME, i HAVE used UPROPERTY(), UPROPETY(EditAnywhere, VisibleAnywhere, EditDefaultsOnly, EditAnywhere, BlueprintReadWrite, AND BlueprintReadOnly) Basically every possible combination of UPROPERTY onto pointers. I have also tried removing the UPROPERTY entirely.

Please, any help is much appreciated. I cant exactly work on UE5 if i cant even use components.

Have you added the include for this httpComp class ?

Also, this will only print if bIsReplacementHost is true. Better use “IsValid()” then a simple if too.

I’ve modified it so that you see the includes on the header file.

Due to the post being too long, i trimmed off the Else statement that was triggering on if(HTTPCompVariable). It would constantly say “Comp is invalid” every tick and was very annoying. instead, when running, i look out to see if the variable displays on screen. I removed the if and tested it and got the same result

The code seems correct to me. Have you tried to reparent your blueprint class ?

2 Likes

I just switched to a diff parent class and switched back and now it works. Must be some kind of bug. thanks for the help

2 Likes