Я сделал актера пикапа и актера спавнера. После 2 дней отладки и исследования мне удалось создать актера, но статическая сетка не породила его вместе с ним. Пожалуйста помоги!
Параметры задачи:
Код: 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.");
}
Задача ещё не решена.
Других решений пока нет …