SetHiddenInGame Replication?


I created an actor with a mesh component, and added an enable and disable function, like this:

header file:

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "GameFramework/Actor.h"
#include "Barrel.generated.h"

class MYGAME_API ABarrel : public AActor
	// Sets default values for this actor's properties

	/** StaticMeshComponent to represent the pickup in the level */
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Replicated, Category = "Barrel")
	UStaticMeshComponent* BarrelMesh;

	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

	/** Override function to replicate this class properties */
	void GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const override;

	void EnableBarrel();
	void DisableBarrel();

cpp file:
// Fill out your copyright notice in the Description page of Project Settings.

#include "MyGame.h"
#include "Barrel.h"

// Sets default values
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = false;

	//Create the static mesh component 
	BarrelMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BarrelMesh"));

	// Set the SphereComponent as the root component
	RootComponent = BarrelMesh;


// Called when the game starts or when spawned
void ABarrel::BeginPlay()


void ABarrel::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const

	// Replicate to everyone
	DOREPLIFETIME(ABarrel, BarrelMesh);

void ABarrel::EnableBarrel()


void ABarrel::DisableBarrel()

In the GameMode, there’s a check in DefaultTimer() that runs it every 5 seconds (testing purposes), effectivelly toggling the barrel visibility and collision.

My problem is: It works on the listen server (in the editor), but it does not work on the client.
Collision is disabled, but the actor do not disappear.

Any idea how can I replicate the SetHiddenInGame() call?

Thank you in advance!

I managed to solve this using a NetMulticast function.
Thanks everyone who read the question in hopes to help! :slight_smile:

You saved my life. Thank you for following up with the solution, been banging my head on this for a while.