What's the different between SetHiddenInGame and SetVisibility functions in SceneComponent. Both have the same code

In UE what’s the different between the SetHiddenInGame and SetVisibility functions in SceneComponent? Both have the same code!

void USceneComponent::SetVisibility(const bool bNewVisibility, const USceneComponent::EVisibilityPropagation PropagateToChildren)
{
	bool bRecurseChildren = (PropagateToChildren == EVisibilityPropagation::Propagate);
	if ( bNewVisibility != GetVisibleFlag() )
	{
		bRecurseChildren = bRecurseChildren || (PropagateToChildren == EVisibilityPropagation::DirtyOnly);
		SetVisibleFlag(bNewVisibility);
		OnVisibilityChanged();
	}

	const TArray<USceneComponent*>& AttachedChildren = GetAttachChildren();
	if (bRecurseChildren && AttachedChildren.Num() > 0)
	{
		// fully traverse down the attachment tree
		// we do it entirely inline here instead of recursing in case a primitivecomponent is a child of a non-primitivecomponent
		TInlineComponentArray<USceneComponent*, NumInlinedActorComponents> ComponentStack;

		// prime the pump
		ComponentStack.Append(AttachedChildren);

		while (ComponentStack.Num() > 0)
		{
			USceneComponent* const CurrentComp = ComponentStack.Pop(/*bAllowShrinking=*/ false);
			if (CurrentComp)
			{
				ComponentStack.Append(CurrentComp->GetAttachChildren());

				if (PropagateToChildren == EVisibilityPropagation::Propagate)
				{
					CurrentComp->SetVisibility(bNewVisibility, EVisibilityPropagation::NoPropagation);
				}

				// Render state must be dirtied if any parent component's visibility has changed. Since we can't easily track whether 
				// any parent in the hierarchy was dirtied, we have to mark dirty always.
				CurrentComp->MarkRenderStateDirty();
			}
		}
	}
}

void USceneComponent::SetHiddenInGame(const bool bNewHiddenGame, const USceneComponent::EVisibilityPropagation PropagateToChildren)
{
	bool bRecurseChildren = (PropagateToChildren == EVisibilityPropagation::Propagate);
	if ( bNewHiddenGame != bHiddenInGame )
	{
		bRecurseChildren = bRecurseChildren || (PropagateToChildren == EVisibilityPropagation::DirtyOnly);
		bHiddenInGame = bNewHiddenGame;
		OnHiddenInGameChanged();
	}

	const TArray<USceneComponent*>& AttachedChildren = GetAttachChildren();
	if (bRecurseChildren && AttachedChildren.Num() > 0)
	{
		// fully traverse down the attachment tree
		// we do it entirely inline here instead of recursing in case a primitivecomponent is a child of a non-primitivecomponent
		TInlineComponentArray<USceneComponent*, NumInlinedActorComponents> ComponentStack;

		// prime the pump
		ComponentStack.Append(AttachedChildren);

		while (ComponentStack.Num() > 0)
		{
			USceneComponent* const CurrentComp = ComponentStack.Pop(/*bAllowShrinking=*/ false);
			if (CurrentComp)
			{
				ComponentStack.Append(CurrentComp->GetAttachChildren());

				if (PropagateToChildren == EVisibilityPropagation::Propagate)
				{
					CurrentComp->SetHiddenInGame(bNewHiddenGame, EVisibilityPropagation::NoPropagation);
				}

				// Render state must be dirtied if any parent component's visibility has changed. Since we can't easily track whether 
				// any parent in the hierarchy was dirtied, we have to mark dirty always.
				CurrentComp->MarkRenderStateDirty();
			}
		}
	}
}

One works in the editor, also.

1 Like

one thing ive noticed is hidden in game is replicated but visibility isnt so if you want to hide an object from only one player use visibility

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.