x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

SetHiddenInGame Replication?

Hello,

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"
 
 UCLASS()
 class MYGAME_API ABarrel : public AActor
 {
     GENERATED_BODY()
     
 public:    
     // Sets default values for this actor's properties
     ABarrel();
 
     /** 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
 ABarrel::ABarrel()
 {
      // 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;
 
     SetReplicates(true);
 }
 
 // Called when the game starts or when spawned
 void ABarrel::BeginPlay()
 {
     Super::BeginPlay();
 
     EnableBarrel();
 }
 
 void ABarrel::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
 {
     Super::GetLifetimeReplicatedProps(OutLifetimeProps);
 
     // Replicate to everyone
     DOREPLIFETIME(ABarrel, BarrelMesh);
 }
 
 void ABarrel::EnableBarrel()
 {
     BarrelMesh->SetHiddenInGame(false);
     BarrelMesh->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
 
 }
 
 void ABarrel::DisableBarrel()
 {
     BarrelMesh->SetHiddenInGame(true);
     BarrelMesh->SetCollisionEnabled(ECollisionEnabled::NoCollision);
 }
 

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!

Product Version: UE 4.7
Tags:
more ▼

asked May 27 '15 at 02:15 AM in C++ Programming

avatar image

Zoc
188 16 13 24

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

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

more ▼

answered May 27 '15 at 05:26 AM

avatar image

Zoc
188 16 13 24

avatar image OKomili Dec 11 '16 at 02:24 AM

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

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question