Hi, have problems with tutorial code c++, method won’t work because
SpawnActor failed because no class was specified
void ASpawnVolume::SpawnPickup()
{
if (GEngine)
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, TEXT("ASpawnVolume::SpawnPickup()"));
//if (WhatToSpawn != NULL)
//{
UWorld* const World = GetWorld();
if (World)
{
FActorSpawnParameters SpawnParams;
SpawnParams.Owner = this;
SpawnParams.Instigator = Instigator;
FVector SpawnLocation = GetRandomPointInVolume();
FRotator SpawnRotation;
SpawnRotation.Yaw = FMath::FRand() * 360.f;
SpawnRotation.Pitch = FMath::FRand() * 360.f;
SpawnRotation.Roll = FMath::FRand() * 360.f;
APickup* SpawnedPickup = World->SpawnActor<APickup>(WhatToSpawn, SpawnLocation, SpawnRotation, SpawnParams);
if (!SpawnedPickup)
UE_LOG(LogTemp, Warning, TEXT("SpawnVolume::SpawnPickup not exist"))
else
UE_LOG(LogTemp, Warning, TEXT("SpawnVolume::SpawnPickup spawned succesfully"))
}
else
UE_LOG(LogTemp, Warning, TEXT("ASpawnVolume::SpawnPickup 2"))
//}
//else
// UE_LOG(LogTemp, Warning, TEXT("ASpawnVolume::SpawnPickup 1"))
}
Any idea what’s the problem? Because i searched for WhatToSpawn in all my files and source from https://d26ilriwvtzlb.cloudfront.net/8/85/Source_4_4.zip and only places where it occurs are
in SpawnVolume.h
#pragma once
#include "GameFramework/Actor.h"
#include "SpawnVolume.generated.h"
/**
*
*/
UCLASS()
class TUT_THIRD_CODE_API ASpawnVolume : public AActor
{
GENERATED_UCLASS_BODY()
UPROPERTY(VisibleInstanceOnly, Category = Spawning)
TSubobjectPtr<UBoxComponent> WhereToSpawn;
UPROPERTY(EditAnywhere, Category = Spawning)
TSubclassOf<class APickup> WhatToSpawn;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Spawning)
float SpawnDelayRangeLow;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Spawning)
float SpawnDelayRangeHigh;
UFUNCTION(BlueprintPure, Category = Spawning)
FVector GetRandomPointInVolume();
virtual void Tick(float DeltaSeconds);
void EnableSpawning();
void DisableSpawning();
private:
bool bSpawningEnabled;
float GetRandomSpawnDelay();
float SpawnDelay;
void SpawnPickup();
float SpawnTime;
};
and the method above, so i don’t know where it should be filled, i commented the check if (WhatToSpawn != NULL) because WhatToSpawn never was something rather than NULL
to test i even copied all code from tutorial source (replaced only class names because of another project naming) and WhatToSpawn still NULL, but i sure it worked before xD, of course there are may be some errors/misses in blueprints, but i can’t figure it out