# Actor reference clearing on blueprint compilation.

**URL:** <https://forums.unrealengine.com/t/actor-reference-clearing-on-blueprint-compilation/2149175>\
**Category:** C++\
**Tags:** reference, reflection, unreal-engine, Blueprint, question, CPP\
**Created:** [November 24, 2024, 11:01pm UTC](https://forums.unrealengine.com/t/actor-reference-clearing-on-blueprint-compilation/2149175 "2024-11-24T23:01:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vahan\_Davtian](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Vahan\_Davtian](https://forums.unrealengine.com/u/Vahan_Davtian)\
**Post date:** [November 24, 2024, 11:01pm UTC](https://forums.unrealengine.com/t/actor-reference-clearing-on-blueprint-compilation/2149175/1 "2024-11-24T23:01:56Z")

</div>

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.

```auto
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`

```auto
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.
