How to know when an actor is not rendered? [Partially-solved]

I have a couple of actors with custom movement.
Movement is controlled from the tick event.

void AMyActor::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
   //Custom movement code here
}

I would like to disable the tick event if no player is watching (the actor is not rendered).
Because it consumes CPU time an it is a waste.

Does anyone know how to do it?

Thank you very much!!


The problem is Partially-solved (read my last post).
Just a couple of details are missing to be complete.


I think you have to use the dot product.

Sorry, maybe I explained it wrong… the idea is that it only moves when it is rendered. (It only renders when some player looks at it).

USkeletalMesh has a similar option:


	VisibilityBasedAnimTickOption = EVisibilityBasedAnimTickOption::OnlyTickPoseWhenRendered;

But in my specific case I am using a static mesh that has not bones.

Thank you very much for your response!!

Well, the default dynamic occlusion occludes everything that is not rendered, if it were a skeletal mesh, the same but if you want to occlude animations there is an option for that.

The problem is that the movement still works even if the actor is not visible (Even if occluded).
It has not animations…

This sounds better…
I’ll look into it.
Thanks!!

ok im wrong, this is in blueprint:

1 Like

I will try it…
thanks a lot!!

I copied some lines of code from UMovementComponent
From a function called.

ShouldSkipUpdate(float DeltaTime)

It seems to work.

bool AMyActor::ShouldSkipUpdate(float DeltaTime) const
{
	if (!IsValid(StaticMesh))
	{
		return true;
	}
	
	if (IsNetMode(NM_DedicatedServer))
	{
		// Dedicated servers never render
		return true;
	}
	
	if (StaticMesh->Mobility != EComponentMobility::Movable)
	{
		return true;
	}

	const float RenderTimeThreshold = 0.41f;
	UWorld* TheWorld = GetWorld();
	if (TheWorld->TimeSince(StaticMesh->GetLastRenderTime()) <= RenderTimeThreshold)
	{
		return false; // Rendered, don't skip it.
	}
	return true;
}

This is definitely a problem with replication of the movement because it is an actor that applies damage.

If it does not move on the dedicated server the client and server will have different positions

So the problem now is. If it doesn’t render on the client, it must not move on the server…

Another problem is that the Tick function is not disabled (it just doesn’t move when not rendering). So this is consuming CPU time anyway and the ideally is disable it completely.

Help with this is welcome!!