我做了一个皮卡演员和一个产卵演员。经过2天的调试和研究后,我设法产生了actor,但是静态网格物体却没有随之产生它。请帮忙!
问题参数:
代码:PickupSpawner.h
#pragma once
#include "Pickup.h"
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "PickupSpawner.generated.h"
UCLASS()
class COOKBOOK_API APickupSpawner : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
APickupSpawner();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
UPROPERTY(EditAnywhere)
USceneComponent* Scene;
void SpawnPickup();
UPROPERTY(EditAnywhere)
TSubclassOf<class APickup> PickupToSpawn;
};
PickupSpawner.cpp
#include "PickupSpawner.h"
#include "Kismet/KismetMathLibrary.h"
#include "Public/TimerManager.h"
#include "Engine/World.h"
// Sets default values
// Sets default values
APickupSpawner::APickupSpawner()
{
// 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;
Scene = CreateDefaultSubobject<USceneComponent>("Scene");
}
// Called when the game starts or when spawned
void APickupSpawner::BeginPlay()
{
Super::BeginPlay();
FTimerHandle DummyHandle;
GetWorldTimerManager().SetTimer(DummyHandle, this, &APickupSpawner::SpawnPickup, 3.f, true);
}
// Called every frame
void APickupSpawner::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void APickupSpawner::SpawnPickup()
{
FTransform SpawnTransform = Scene->GetComponentTransform();
FVector SpawnLocation = SpawnTransform.GetLocation();
SpawnLocation.X += FMath::RandRange(-200.0f, 200.0f);
SpawnTransform.SetLocation(SpawnLocation);
GetWorld()->SpawnActor<APickup>(APickup::StaticClass(), SpawnTransform);
GLog->Log("Spawned the UsefulActor.");
}