Hi again guys,
I have a custom Actor class, with its own variables, and I need to initialize & set their value before spawning them - e.g. Mesh, Duration,etc.
How can I do that? I mean, spawning doesn’t let you specify the constructor, just the default one.
Alderbit
(Alderbit)
2
For this I would usually use SpawnActorDeferred followed by FinishSpawningActor after setting the property values.
UWorld* World = GetWorld();
if( World )
{
AMyActor* NewActor = World->SpawnActorDeferred<AMyActor>(
MyActorClass, FTransform::Identity, nullptr, nullptr, ESpawnActorCollisionHandlingMethod::AlwaysSpawn);
// initialize NewActor...
UGameplayStatics::FinishSpawningActor(NewActor, SpawnTransform);
}
The actor isn’t actually constructed until the FinishSpawningActor call so don’t forget that part!
1 Like
Thanks!
That’s exactly what I needed