Access violation on non-null newly spawned actor

This is not the first time I’ve had this issue, but I haven’t been able to actually figure out what’s causing it. I’m spawning an actor in every playerstate which contains an audio component. The actor is attached to the player’s camera on character posession, and attenuation settings are applied. Most of the time this works fine, but after a few travels (which destroys and respawns the actor) the game will crash with an access violation. Previously this was happening inside the actor, in a function which accessed the AudioComponent. I’ve now reorganized things so that the AudioComponent is never accessed directly, hoping this would solve the issue… it sort of did, but I’m STILL getting crashes here:

		VoIPReciever = PWPlayerState->GetVoIPReciever();
		if (VoIPReciever) {
			VoIPReciever->AttachToComponent(VRReplicatedCamera, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
			UE_LOG(LogTemp, Log, TEXT("AProxyWarVRCharacter::OnRep_PlayerState() -> Attached VoIPReciever to camera"));
		}

The given reason for the crash is an access violation on VoIPReciever->AttachToComponent. WHY in the world is this happening? Surely VoIPReciever is not null, otherwise if (VoIPReciever) would be false, right? My best guess is that the actor just hasn’t been fully initialized… so I’ve tried waiting until PostInitializeComponents is called on the actor, but that doesn’t seem to do anything. I’m stumped!

EDIT: based on the crash report, it seems as if the issue is that my root USceneComponent is not valid for some reason:

ProxyWarVR!USceneComponent::AttachToComponent()
ProxyWarVR!AActor::AttachToComponent()

Hi there, I don’t know if it’ll help, but I’ve found the UAudioComponent to be very unstable.
I don’t know what’s insidey our GetVoIPReceiver(), but if it returns a UAudioComponent as a reference, that may be causing it.

I hope this helps.

I haven’t had this issue in over 6 months, but I’m not really sure what I did to fix it. VoIPReciever is an actor though, which contains an audio component.

In any case this, and your issue as well, seem like garbage collection issues. This would presumably be fixed with a UPROPERTY declaration in the header.