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"

How do I replicate a function in C++?

I'm trying to make a multiplayer game based off of capture the flag, and I've setup a function that can attach the flag to the player, but I can't figure out how to replicate it. I've tried to call UFUNCTION(Client, Reliable) but that doesn't work. What should I do?

Header:

 #pragma once
 
 #include "CoreMinimal.h"
 #include "GameFramework/Character.h"
 #include "SCharacter.generated.h"
 
 UCLASS()
 class CAPTURETHEFLAG_API ASCharacter : public ACharacter
 {
     GENERATED_BODY()
 
 public:
     // Sets default values for this character's properties
     ASCharacter();
 
 protected:

     UFUNCTION(Client, Reliable)
     void AttachFlagToPlayer();
 
     // More code...
 
 };


CPP:

 #include "SCharacter.h"
 #include "Net/UnrealNetwork.h"
 #include "SFlag.h"
 
 
 // Sets default values
 ASCharacter::ASCharacter()
 {
     // Component setup...
 }
 
 
 // Called every time we want to interact with the flag
 void ASCharacter::Interact()
 {
     if (AbleToInteract())
     {
         // Code...
 
         // Attach the flag to ourself
         AttachFlagToPlayer();
     }
 }
 
 
 void ASCharacter::AttachFlagToPlayer_Implementation()
 {
 
     FlagReference->AttachToComponent(GetMesh(), FAttachmentTransformRules::SnapToTargetNotIncludingScale, WeaponAttachSocketName);
 }
Product Version: UE 4.21
Tags:
more ▼

asked Feb 08 '19 at 12:16 AM in C++ Programming

avatar image

Void_Gabe
26 6 12 12

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

I figured it out! I thought a variable that I was trying use was replicated because I marked it as replicated, but it wasn't being changed on the server, and I guess it does need to be changed on the server to be replicated.

more ▼

answered Mar 05 '19 at 09:27 PM

avatar image

Void_Gabe
26 6 12 12

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
 //Works on client only
 UFUNCTION(Client)
 void DoSomething();


 //Works on server only
 UFUNCTION(Server)
 void DoSomething();

 //Works on Server and Client
 UFUNCTION(NetMulticast)
 void DoSomething();

more ▼

answered Feb 08 '19 at 06:51 AM

avatar image

Yusuf
36 3 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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