Download

access violation on SetStaticMesh

Hey iam converting some of my BP work over to C++ and now iam struggling over an access violation i cant explain to myself

Code wich well causes the exeption


Root->SetStaticMesh(bStages[bIdToSet].bStageMesh);

Snippets from the Headerfile



USTRUCT(BlueprintType)
struct FConstructionStages
{
	GENERATED_USTRUCT_BODY()

	
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Construction)
	UStaticMesh* bStageMesh;
	
	
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Construction)
	int32	bStagePoints;

	
	FConstructionStages()
	{
		bStagePoints = 0;

	}

	FConstructionStages(UStaticMesh* bMesh, int32 bPoints) {
		bStagePoints = bPoints;
		bStageMesh = bMesh;

	}

}; 
.
.
.
.
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = Construction)
	TSubobjectPtr<UStaticMeshComponent> Root;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Construction)
	TArray<FConstructionStages> bStages;



Code from the source file



AConstruction_Foundation::AConstruction_Foundation(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	//Load all needed Mesh References
	static ConstructorHelpers::FObjectFinder<UStaticMesh> bStage1Mesh(__STAGE1MESHREF);
	static ConstructorHelpers::FObjectFinder<UStaticMesh> bStage2Mesh(__STAGE2MESHREF);
	static ConstructorHelpers::FObjectFinder<UStaticMesh> bStage3Mesh(__STAGE3MESHREF);

	//Set the Stage1 Mesh
	if (bStage1Mesh.Object)
		Root->SetStaticMesh(bStage1Mesh.Object);
		//Brush_Mesh->SetStaticMesh(StaticMeshOb_AW2.Object);

	bStagePointsMax = __POINTS_MAX;

	if (bStage2Mesh.Object)
		bStages.Add(FConstructionStages(bStage2Mesh.Object, __POINTS_STAGE2));

	if (bStage3Mesh.Object)
		bStages.Add(FConstructionStages(bStage3Mesh.Object, __POINTS_STAGE3));

	
}


when i create a bp of that actor everything is set fine. the array of my custom structure is populated with the data i want etc. now when i execute the line of code in the first codebox above i get that access violation i cant explain. can someone tell me what iam missing here?

Edit: Oh and iam useing 2 classes the parent class contains the code etc, the child class is populated with the data and is used as the blueprint class everything works fine i can acess all my variables and stuff just the SetStaticMesh doesnt work :confused:

Do you assign an object to the Root pointer anywhere?

The root is a ustaticmeshcomponent wich is set properly, it has a starting model wich is working fine