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"

Deleting actor with raycast but it's not updated to client

I think I'm asking again something very simple but I just don't get whats wrong whit this

I'm trying to build Consumable actor item like in this tutorial but for some reason when I "click" on Actor its only destroyed on server when it should be seen by everyone. Clients can click on actor but only the server sees it been destroyed. And for some reason clients don't see Traces at all

Thanks for help!

Player.h

 #include "GameFramework/Character.h"
 #include "Player.generated.h"
   
   UCLASS()
 class Game_API APlayerSurvivor : public ACharacter
 {
     GENERATED_BODY()
 public:
       void Use();
 
     class AConsumableActor* GetUsableInView();
 
     UFUNCTION(Server, Reliable, WithValidation)
     void ServerUse();
 
     void ServerUse_Implementation();
 
     bool ServerUse_Validate();
  }

Player.cpp

 #include "Game.h"
 #include "Player.h"
 #include "ConsumableActor.h"
 #include "Net/UnrealNetwork.h"  
   
 void APlayer::Use()
 {
     if (Role == ROLE_Authority)
     {
         AConsumableActor* Usable = GetUsableInView();
         if (Usable)
         {
             Usable->OnUsed(this);
         }
     }
     else
     {
         ServerUse(); 
     }
 }
 AConsumableActor* APlayer::GetUsableInView()
 { //handles Trace
     FVector CamLoc;
     FRotator CamRot;
 
     if (Controller == NULL)
         return NULL;
 
     Controller->GetPlayerViewPoint(CamLoc, CamRot);
     const FVector Direction = CamRot.Vector();
     const FVector TraceStart = CamLoc;
     const FVector TraceEnd = TraceStart + (Direction *5000.f);
 
     FCollisionQueryParams TraceParams(FName(TEXT("TraceTestConsumable")), true, this);
     TraceParams.bTraceAsyncScene = true;
     TraceParams.bReturnPhysicalMaterial = false;
     TraceParams.bTraceComplex = true;
 
     FHitResult Hit(ForceInit);
     GetWorld()->LineTraceSingleByChannel(Hit, TraceStart, TraceEnd, ECC_Visibility, TraceParams);
     
     DrawDebugLine(GetWorld(), TraceStart, TraceEnd, FColor::Red, true, 1.0f);
 
     return Cast<AConsumableActor>(Hit.GetActor());
 }
 void APlayer::ServerUse_Implementation()
 {
     Use();
 }
 bool APlayer::ServerUse_Validate()
 {
     return true;
 }

And ConsumableActor.h

 #include "GameFramework/Actor.h"
 #include "Net/UnrealNetwork.h"
 #include "ConsumableActor.generated.h"
 
 UCLASS(ABSTRACT)
 class Game_API AConsumableActor: public AActor
 {
     GENERATED_BODY()
 public:    
     AConsumableActor(const FObjectInitializer& ObjectInitializer);
 
     UPROPERTY(VisibleAnywhere, Category = "Mesh")
         UStaticMeshComponent* MeshComp;
         
     virtual void OnUsed(APawn* InstigatorPawn);
 
     UFUNCTION()
     void OnPickedUp();
 
     UPROPERTY(Transient, ReplicatedUsing = OnPickedUp)
         bool CIsActive;
 };

ConsumableActor.cpp

 #include "Game.h"
 #include "ConsumableActor.h"
 
 AConsumableActor::AConsumableActor(const class FObjectInitializer& ObjectInitializer)
     : Super(ObjectInitializer)
 {
     MeshComp = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("Mesh"));
     RootComponent = MeshComp;
 
     CIsActive = false;
 }
 void AConsumableActor::OnUsed(APawn* InstigatorPawn)
 {
 
     CIsActive = true;
     OnPickedUp();
 }
 void AConsumableActor::OnPickedUp()
 {
     if (CIsActive)
     {
         if (MeshComp)
         {        //Destroys actor
             MeshComp->SetVisibility(false);
             MeshComp->SetSimulatePhysics(false);
             MeshComp->SetCollisionEnabled(ECollisionEnabled::NoCollision);
         }
     }
 }
 void AConsumableActor::GetLifetimeReplicatedProps(TArray<FLifetimeProperty> & OutLifetimeProps) const
 {
     Super::GetLifetimeReplicatedProps(OutLifetimeProps);
 
     DOREPLIFETIME(AConsumableActor, CIsActive);
 }


Product Version: UE 4.13
Tags:
more ▼

asked Sep 27 '16 at 10:27 PM in C++ Programming

avatar image

Sven97
5 2 2 4

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

1 answer: sort voted first

I quess I dont need answer anymore

more ▼

answered Oct 03 '16 at 06:02 PM

avatar image

Sven97
5 2 2 4

(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