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();
}
}
}
}