Disable an Actor

So I elected to implement an empty class and called it HelperClass, so I can just access its static functions. The following are the methods I used, you can always extend this to disable other things you want to as well:

void HelperClass::deactivateActor(AActor* actor)
{
	// Deactivate this actor
	actor->SetActorHiddenInGame(true);
	actor->SetActorEnableCollision(false);
	actor->SetActorTickEnabled(false);

	// Call on children
	TArray<AActor*> children;
	actor->GetAllChildActors(children);			// Actual children
	actor->GetAttachedActors(children, false);	// Attached actors. Don't reset array
	for (auto child : children)
		deactivateActor(child);

}

void HelperClass::activateActor(AActor* actor)
{
	// Activate this actor
	actor->SetActorHiddenInGame(false);
	actor->SetActorEnableCollision(true);
	actor->SetActorTickEnabled(true);

	// Call on children
	TArray<AActor*> children;
	actor->GetAllChildActors(children);			// Actual children
	actor->GetAttachedActors(children, false);	// Attached Actors. Don't reset array
	for (auto child : children)
		activateActor(child);
}
1 Like

Let me argue on this.

The fact that a feature has not been implemented, does not mean that it’s because it’s useless or because the product is better without that feature.
Case in point: Blender’s ridiculous UI, beginning with the Right-Click Select.

Now let me tell you: I am using Unity since about 15 years, and I CONTINUOUSLY activate and deactivate objects in my scene hierarchy.
IT IS EXTREMELY USEFUL for a series of reasons.
If you want me to expand on this, I’ll do.

Anyway, I have a couple of basic questions on the matter:

  1. Is it so difficult to simply put a checkbox on each actor, that will it out of all the systems? I am asking honestly, because I am not a professional programmer, so there may be some very good reasons for not implementing this, apart the “we worked like this for 24 years, we don’t need to add this feature now”.
    In Unity, the FIRST and most important parameter of any object is if that object is actually active in any way, or just waiting to be activated.

  2. As I REALLY want this feature, can someone point out to which is the most stable and efficient way to implement it as described?
    Meaning like a simple checkbox in the Editor, that will ensure the immediate deactivation of each and every function of the actor when the game is launched.

  3. Possible idea: is it possible to “save” an actor in some kind of buffer or cache where nothing of it will be active?

1 Like

If you want to build from source, you could easily add a SetActive() function to Actor that toggles Ticking and recursively toggles off all components. You could set up a function called on editor changes that calls this based on toggling a bool prop on the actor.

You can also do it with a plugin, or with a helper library, as other people in this thread have pointed out.

If you want it to work “just like Unity” then the first option is probably the way to go. If you have issues with making changes to the base engine code, then you’ll have to roll it another way.

1 Like