Cant use Pointer for TArray

Im trying to create a TArray pointer to store a link to a const TArray reference outputed by a Reference Skeleton.

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "Components/ActorComponent.h"
#include "SpriterSkeletonComponent.generated.h"


UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class SPRITEREPICTEST_API USpriterSkeletonComponent : public UActorComponent
{
	GENERATED_BODY()

public:	
	// Sets default values for this component's properties
	USpriterSkeletonComponent();

	// Called when the game starts
	virtual void BeginPlay() override;
	
	// Called every frame
	virtual void TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction ) override;

	UPROPERTY(BlueprintReadOnly) // ERROR: Inappropriate '*' on variable of type 'TArray', cannot have an exposed pointer to this type.
	TArray<FTransform>* BoneTransforms;

	TWeakObjectPtr<USkeletalMeshComponent> SkeleComponent;
};

Tried putting the “*” inside of the <> and i get the same Error.
This is the code for obtaining the data.

SkeleComponent = (USkeletalMeshComponent*)GetOwner()->GetComponentByClass(USkeletalMeshComponent::StaticClass());
BoneTransforms = SkeleComponent->SkeletalMesh->RefSkeleton.GetRefBonePose(); // RETURNS: const TArray<FTransform>&
1 Like

Blueprints don’t support pointers of any type except UObject pointers (because they can only be used in pointers anyway). Because of that UHT don’t know what to do with this varable and give you error, so remove BlueprintReadOnly, if that does not work remove UPROPERTY() all together and manually manage that pointer, null it when object it points to is deleted, i recommend you do that anyway because i’m not sure if TArray pointers would work properly in reflection system.

What you trying to do is quite unconventional (and probably not recommended) in UE4, i never seen case of TArray pointer in UE4 (and i seen a lot of UE4 code ;p). Common practice in UE4 for something like that is to create functions with reference argument to interact with forgain array and modify it, like GetAllActorsOfClass for example:

TArray* are not a supported UPROPERTY type. The only way to do what you are trying to do is remove the UPROPERTY and do it without that support. It’s kind of dangerous though since the object that it is pointing to can be garbage collected and you’d never know until you accessed it and crashed.

1 Like