Hi,
Basically I’m trying to work out how to spawn pawns within the 2D environment.I know how to spawn GetWorld()->SpawnActor() etc. but my issues is the fact that the navigation system can’t find spawnable areas. I’ve set up a NavMesh and tried doing this:
ATest2DCharacter* ASpawnpoint::SpawnCharacter(UWorld* world, FVector location, FRotator rotation, TSubclassOf<class ATest2DCharacter> classToSpawn) {
int count = 0;
FNavLocation nav;
ATest2DCharacter* character = nullptr;
while (character == nullptr && count < 10) {
FActorSpawnParameters params;
params.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
world->GetNavigationSystem()->GetRandomPointInNavigableRadius(location, 100, nav);
character = world->SpawnActor<ATest2DCharacter>(classToSpawn, nav.Location, rotation, params);
count++;
}
if (character != nullptr) {
character->SpawnDefaultController();
return dynamic_cast<ATest2DCharacter*>(character);
}
else return nullptr;
}
I’m sure you can use things like Agents to make this work. So far my level is just the default 2D sidescroller project.
If someone could show me a working example within Blueprint or C++ or how to make it work, that would be great thanks!