Hi! I’m trying to spawn actor with SpawnActorDeferred and it appears in level and even interacts with other actors, but it is invinsible.
When I try doing the same thing with SpawnActor everything works properly.
Hi! I’m trying to spawn actor with SpawnActorDeferred and it appears in level and even interacts with other actors, but it is invinsible.
When I try doing the same thing with SpawnActor everything works properly.
I am using Deffered Spawning without any problems.
When they spawn, did you find them in existing actor list on the right panel in UE IDE?
Did you check hidden/visibility flags of these actors?
All spawned actors appear in actor list.
All hidden flags are set to false. Visible flags are set to true.
Interesting, this is snippet from my code:
AAsteroid* asteroid = World->SpawnActorDeferred<AAsteroid>(AAsteroid::StaticClass(), SpawnTransform);
asteroid->FinishSpawning(SpawnTransform);
In your case, if there would be problems with GetWorld(), then the actors wouldn’t have appeared in the list.
In your code, the first argument is called ActorToSpawn, what if you change it to following to make it similar to my code:
GetWorld()->SpawnActorDeferred<ACPP_Projectile>(ACPP_Projectile::StaticClass(), ProjectileTransform);
Another idea may be their spawn transform. Maybe they get collision event where they get spawned? Perhaps you can override destructor via following function to print logs? What I mean is that maybe your actor’s visible layer holding the mesh gets destroyed by your game logic right after spawn, but the actor itself stays alive?
void EndPlay(const EEndPlayReason::Type EndPlayReason)
I don’t think that I can use your first solution, as ActorToSpawn is a blueprint class. In this case it is BP_Projectile, which is derived from CPP_Projectile. It works fine with SpawnActor so I guess there is nothing wrong with it.
As for your second suggestion, I don’t understand how to override destructor to print logs. Could you explain how to do it?
In the parent class, CPP_Projectile do following in header:
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
In the source file:
void ACPP_Projectile ::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
Super::EndPlay(EndPlayReason);
UE_LOG(LogTemp, Warning, TEXT("EndPlay() got called"));
}
}
It will print logs when Projectile gets destroyed (in case they get destroyed right after they spawn). Maybe there is a problem with the mesh that you selected.
I suggest you to try StaticClass approach without BP, just with CPP parent. Maybe that will give you a clue (maybe there has to be done something specific when spawning bp class in a deferred way).
When I used SpawnActorDeferred, it somehow messed up my transform and changed scale to (1400, 0, 0).
I had to set the second argument of FinishSpawning to true and now it’s working properly.
Thanks for help with finding the issue.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.