Access violation error with custom sound node class

I’m running into issues when I drag a soundcue containing a custom USoundNode and USoundWave. The node works and plays fine when played from the sound cue editor, but crashes when I drag it into a scene and hit play. I’m posting here on advice given on the Unreal C++ programming forum here. You can find the source code there too, along with the editor log. To be honest, I’m really not sure this is a bug as the access violation appears in my code. It could well be something I’m doing wrong. Here is the call stack:

UE4Editor-CsoundUnrealProject.dll!USoundNodeTest::ParseNodes(FAudioDevice * AudioDevice, const unsigned __int64 NodeWaveInstanceHash, FActiveSound & ActiveSound, const FSoundParseParameters & ParseParams, TArray<FWaveInstance *,FDefaultAllocator> & WaveInstances) Line 39 C++
UE4Editor-Engine.dll!00007ffd5fb30264() Unknown
UE4Editor-Engine.dll!00007ffd5fdd2bc3() Unknown
UE4Editor-Engine.dll!00007ffd5fe07ec6() Unknown
UE4Editor-Engine.dll!00007ffd5fe8c22f() Unknown
UE4Editor-UnrealEd.dll!00007ffd5e052329() Unknown
UE4Editor-UnrealEd.dll!00007ffd5eabd8de() Unknown
UE4Editor.exe!00007ff6b72cf02f() Unknown
UE4Editor.exe!00007ff6b72b9fcc() Unknown
UE4Editor.exe!00007ff6b72d1a8a() Unknown
UE4Editor.exe!00007ff6b72d3376() Unknown
[External Code]

And here is the info given by Visual Express when the crash occurs.

Unhandled exception at
0x00007FFD4D72249B
(UE4Editor-CsoundUnrealProject.dll) in
UE4Editor.exe: 0xC0000005: Access
violation reading location
0x00000000000002A0.

If there is a handler for this
exception, the program may be safely
continued.

I’m running Windows 10 on an i5 desktop. I’m not loading any external or 3rd party libraries or plugins. I’d be happy to be told this is all a problem of my own making!

I think it is because the SoundWave object is garbage collected by the engine.

You should make your SoundWave variable a UPROPERTY

UPROPERTY()
MyCustomSoundWave* SoundWave

or if you want to do it the hard way, you can add it to root when you create the object and then manually serialize the object, and remove it from root when you delete it. I would choose the UPROPERTY keyword, it’s easier.