Actor reference clearing on blueprint compilation.

Vahan_Davtian
Sun, 24 Nov 2024 23:01:56 +0000
C++

I’m trying to create a new archetype object, that will serve as a template for spawning other actors of class. SpawnTemplateActor will have ShowInnerProperties so that the template instance can be modified in editor details panel.

if (!SpawnTemplateActor)
{
	SpawnTemplateActor = NewObject<AActor>(this,
		ClassToSpawn, NAME_None, RF_Standalone | RF_ArchetypeObject);
}

I tried some different approaches, seems like creating Archetypes objects is the ideal way as the actors with that flag aren’t “spawned” in editor, so you don’t have to hide/disable them at runtime.

Here’s the declaration of SpawnTemplateActor

UPROPERTY(EditAnywhere, BlueprintReadOnly, meta = (ShowInnerProperties, Instanced), Category = "Properties")
AActor* SpawnTemplateActor{};

But problem is, the reference SpawnTemplateActor gets cleared every time ClassToSpawn is recompiled in editor.

Creating the object in GetTransientPackage fixes the issue, but I do need the reference to be saved, so that doesn’t work either. Was wondering if anyone else has had this issue before. For context, this piece of logic would be part of an ActorSpawner class, that will use the modified class template to spawn it’s instances. Kind of like what UChildActorComponent does, but dynamically.

1 post - 1 participant