Hi everyone,
I’m trying to create a C++ function who can spawn an actor callable in BluePrint.
I want with this function doing the same things than “spawnActor” in BluePrint.
The problem is, when i compile, i got an error, that make a half day i trying to resolve my problem.
Here my code.
My actor class .h:
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include “CoreMinimal.h”
#include “GameFramework/Actor.h”
#include “MyActorTest.generated.h”
UCLASS()
class MYPROJECT2_API AMyActorTest : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor’s properties
AMyActorTest();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
UFUNCTION(BlueprintCallable, Category = "Spawning Actor")
AMyActorTest * SpawnObjectActor(AActor * ActorReference, UClass * ClassReference, FVector Location, FRotator Rotation);
};
And here my .cpp code:
// Fill out your copyright notice in the Description page of Project Settings.
#include “MyProject2.h”
#include “Engine/Level.h”
#include “MyActorTest.h”
// Sets default values
AMyActorTest::AMyActorTest()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don’t need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void AMyActorTest::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AMyActorTest::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
AMyActorTest * SpawnObjectActor(AActor * ActorReference, UClass * ClassReference, FVector Location, FRotator Rotation) {
UWorld* const World = ActorReference->GetWorld();
//AMyActorTest * MySpawnedActor = TSubclassOf<AActor> MyObject;
AActor * MySpawnedActor = ActorReference;
AMyActorTest * ActorTest = new AMyActorTest();
if (World != NULL)
{
World->SpawnActor<AActor>(Location, Rotation);
}
return ActorTest;
}
Here a screenshot of my compiler error:
https://forums.unrealengine.com/filedata/fetch?type=thumb&filedataid=116711
Thanks in advance for who will help me, i don’t know how to resolve my *** problem.