Static template call by blueprint


I would like to create a static method that allow me to spawn actor / attach them to a UActorComponent then set his relative position and rotation to zero.

I would like to be able to callt his method through a blueprint however when I compile I get this error and I don’t know how to fix it :

  • Error ActorHelpers.h(24) : Unrecognized type ‘template’ - type must be a UCLASS, USTRUCT or UENUM

Here ActorHelpers.h :
#pragma once

#include "GameFramework/Actor.h"
#include "ActorHelpers.generated.h"

class BLOODOFEVIL_API AActorHelpers : public AActor
	// Sets default values for this actor's properties

	// Called when the game starts or when spawned
	virtual void BeginPlay() override;
	// Called every frame
	virtual void Tick( float DeltaSeconds ) override;

	UFUNCTION(BlueprintCallable, Category = "Helpers")
	static template<class T>
	T* SpawnActorRelativeToHisParent
		UClass* Class,
		USceneComponent* parent,
		FVector location = FVector::ZeroVector,
		FRotator rotation = FRotator::ZeroRotator,
		AActor* Owner = NULL,
		APawn* Instigator = NULL,
		bool bNoCollisionFail = false
		if (Class == NULL)
			return nullptr;

		T* actor = Cast<T>(GetWorld()->SpawnActor(Class, NAME_None, NULL, NULL, NULL, bNoCollisionFail, false, Owner, Instigator));


		return actor;

I do not believe that templates are supported with blueprint. From the code, we know that T must always be of type AActor. So what you should be doing is AActor* actor = GetWorld()->SpawnActor(Class, NAME_None, NULL, NULL, NULL, bNoCollisionFail, false, Owner, Instigator); and then in your blueprint, cast your return value if you need to. In your code, you should also write a check to ensure that UClass* Class is a subtype of AActor.