SetActorHiddenInGame destroys actor

I have an Actor attached to another actor, the attached Actor has no collider, no mesh, and the tick is disabled. The owner of the attached actor is the parent actor.

If I call attachedActor->SetActorHiddenInGame(true); the attached actor gets destroyed after two seconds. And all attempt to access that attached actor fails with “IsPendingKill”.

Is there any way to prevent the actor from getting unloaded?

When an object is no longer referenced by anything, it gets automatically GarbageCollected. That would explain IsPendingKill.

The solution here would be to store its reference in the Parent.

Admittedly, it’s a bit odd to see behaviour like this caused by just hiding the object. On the other hand, Hidden property is more of a debugging tool - things you want to see in the editor, but not in the game. Consider using object Visibility instead.

There is a TArray on the parent that has a reference to all it’s attached Actors.

Hm, interesting. Could you PrintText after OnDestroyed in the actor that gets hidden. I’m under the impression it might trigger.

Another workaround that comes to mind is to call Hidden on the root component rather than the actor. Or, start using Visibility :slight_smile:

Btw, do you detach the actor when hiding it?

I will try by hidding the RootComponent. That seems a better solution than hidding just the potential mesh that could have.
No, it doesn’t get detached. But just before doing the attach and set hidden. The actor was attached to a character (the character doesn’t get destroyed during this operation)

Asked about the detachment for a specific reason. Detached objects with no collision but with active physics will start falling. They’re destroyed after reaching certain Z. Do not quote me on this, though. Anyway, this does not seem to be the case.

Is there any specific reason you’re using Hidden rather than Visibility?