# UE4 crashes every time I hot reload

**URL:** <https://forums.unrealengine.com/t/ue4-crashes-every-time-i-hot-reload/392332>\
**Category:** Getting Started & Setup\
**Tags:** unreal-engine, crash, CPP, question, hot-reload\
**Created:** [April 30, 2017, 10:04pm UTC](https://forums.unrealengine.com/t/ue4-crashes-every-time-i-hot-reload/392332 "2017-04-30T22:04:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgumley](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mgumley](https://forums.unrealengine.com/u/mgumley)\
**Post date:** [April 30, 2017, 10:04pm UTC](https://forums.unrealengine.com/t/ue4-crashes-every-time-i-hot-reload/392332/1 "2017-04-30T22:04:25Z")

</div>

UE4 crashes every time I hot reload. When I build without the editing running, everything is fine. How can I fix this or at least determine why it’s crashing?

EDIT:  
I believe it has something to do with CreateDefaultSubobject. When hot reloading, does the previous default subject not get destroyed?

EDIT #2:  
I ran the editor in debug mode using the UE4 source from git. The UHierarchicalInstancedStaticMeshComponent class is trying to reference a null ptr when hot reloading. Here is the function. You can see that ClusterTreePtr is not always assigned a value. Why is this?

```
void UHierarchicalInstancedStaticMeshComponent::Serialize(FArchive& Ar)
{
	// On save, if we have a pending async build we should wait for it to complete rather than saving an incomplete tree
	if (Ar.IsSaving())
	{
		if (!IsTreeFullyBuilt())
		{
			BuildTree();
		}
	}

	Super::Serialize(Ar);

	if (Ar.IsLoading())
	{
		ClusterTreePtr = MakeShareable(new TArray<FClusterNode>);
	}
	TArray<FClusterNode>& ClusterTree = *ClusterTreePtr;
	ClusterTree.BulkSerialize(Ar);
	if (Ar.IsLoading() && !BuiltInstanceBounds.IsValid)
	{
		BuiltInstanceBounds = (ClusterTree.Num() > 0 ? FBox(ClusterTree[0].BoundMin, ClusterTree[0].BoundMax) : FBox(0));
	}
}
```

---

<div class="post-metadata">

**Author:** ![Fulltorch](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Fulltorch](https://forums.unrealengine.com/u/Fulltorch)\
**Post date:** [August 29, 2017, 11:56pm UTC](https://forums.unrealengine.com/t/ue4-crashes-every-time-i-hot-reload/392332/2 "2017-08-29T23:56:11Z")

</div>

I have the exact same issue, ran in debug, throws an exception at the same place. I am hoping someone figures it out because i have to restart my editor every time i compile.

---

<div class="post-metadata">

**Author:** ![Ninjin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ninjin](https://forums.unrealengine.com/u/Ninjin)\
**Post date:** [August 30, 2017, 12:11am UTC](https://forums.unrealengine.com/t/ue4-crashes-every-time-i-hot-reload/392332/3 "2017-08-30T00:11:49Z")

</div>

Yeah, changing header files or stuff in the constructor usually breaks hot reload for me, but I believe that’s just normal. Annoying when you just created the class and still adding 1 component after another. However, if you set up all variables and just changing code that is affected in runtime, it doesn’t break.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_f4ea3597](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f4ea3597](https://forums.unrealengine.com/u/anonymous_user_f4ea3597)\
**Post date:** [May 30, 2018, 1:52pm UTC](https://forums.unrealengine.com/t/ue4-crashes-every-time-i-hot-reload/392332/4 "2018-05-30T13:52:38Z")

</div>

Is there an update on this issue? I’m having the same problem

---

<div class="post-metadata">

**Author:** ![TruePHYSX](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TruePHYSX](https://forums.unrealengine.com/u/TruePHYSX)\
**Post date:** [October 12, 2019, 12:21am UTC](https://forums.unrealengine.com/t/ue4-crashes-every-time-i-hot-reload/392332/5 "2019-10-12T00:21:56Z")

</div>

I’m in UE4.22 and I am still having this issue. I am performing this line:

```
if (pATarget != nullptr)

```

and I get a read access violation. I’m starting to think that compiling from within Unreal isn’t the best way to compile. The object itself isn’t null and the name is even associated to a proper object in the level, yet when reading its own variables I get access violations. Is something being garbage collected without me knowing?

---

<div class="post-metadata">

**Author:** ![Ali\_TeamRevived](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ali_teamrevived/32/623450_2.png) [@Ali\_TeamRevived](https://forums.unrealengine.com/u/Ali_TeamRevived)\
**Post date:** [May 25, 2020, 11:15am UTC](https://forums.unrealengine.com/t/ue4-crashes-every-time-i-hot-reload/392332/6 "2020-05-25T11:15:54Z")

</div>

Could you provide some of your code that may be the cause of the crash? Preferably the parts that use HISM.  
ClusterTreePtr always gets value. If it’s null, it seems that the reloading part doesn’t work as intended.

```
 if (Ar.IsLoading())
 {
     ClusterTreePtr = MakeShareable(new TArray<FClusterNode>);
 }

```

And btw, if you’re using 4.15 as stated, maybe they resolved whatever issue it might have.

---

<div class="post-metadata">

**Author:** ![qojat](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@qojat](https://forums.unrealengine.com/u/qojat)\
**Post date:** [May 26, 2020, 7:50pm UTC](https://forums.unrealengine.com/t/ue4-crashes-every-time-i-hot-reload/392332/7 "2020-05-26T19:50:27Z")

</div>

Same issue here in 2020 with UE4.24.

I created a class derived from `UFoliageInstancedStaticMeshComponent` and it crashes the editor every time I hot reload, in the same place the OP indicates, in `D:\UE_4.24\Engine\Source\Runtime\Engine\Private\HierarchicalInstancedStaticMesh.cpp:2044`:

```
void UHierarchicalInstancedStaticMeshComponent::Serialize(FArchive& Ar) {
...
ClusterTreePtr->BulkSerialize(Ar);
...
}
```

Probably because `ClusterTreePtr` is `NULL` for me too.

---

<div class="post-metadata">

**Author:** ![qojat](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@qojat](https://forums.unrealengine.com/u/qojat)\
**Post date:** [May 26, 2020, 7:50pm UTC](https://forums.unrealengine.com/t/ue4-crashes-every-time-i-hot-reload/392332/8 "2020-05-26T19:50:59Z")

</div>

I got the same issue with 4.24. I derived from `UFoliageInstancedStaticMeshComponent` and the editor crashed every time it hot reloaded my class.  
The crash was in the same line the OP indicated 3 years ago: `ClusterTreePtr` probably being `NULL`.

I worked around it by implementing `Serialize` like this:

```

// Workaround for hot reloading
void MyClass::Serialize (FArchive& Ar)
{
	void *ptr = (void *)ClusterTreePtr.Get();
	if (ptr != NULL) {
		Super::Serialize (Ar);
	} else {
		UE_LOG (TmpLog, Warning, TEXT ("Ignored attempt to serialize foliage with NULL ClusterTreePtr"));
	}
}

```

This is probably very wrong, hiding a deeper problem somewhere else, but so far it does the trick. Sometimes I see the Warning, sometimes I don’t, but it hot reloads without issues now.
