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"

UFunction problem

I'm getting errors while trying to set up C++ functions to be accessed from blueprints: I have no idea what I'm supposed to do to get this to work...

cpp:

 AWTCPlayerState::AWTCPlayerState(const FObjectInitializer& ObjectInitializer)
     : Super(ObjectInitializer)
 {
 
     bReplicates = true;
 }
 
 void AWTCPlayerState::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
 {
     DOREPLIFETIME(AWTCPlayerState, Health); 
     //DOREPLIFETIME(AWTCPlayerState, setHealth());
 }
 
 int32 AWTCPlayerState::getHealth(){
     return Health;
 }
 void AWTCPlayerState::setHealth(int32 HP){
     
     if (Role < ROLE_Authority)
     {
         Health = HP;
     }
 }
 
 bool AWTCPlayerState::setHealth_Validate(int32 HP){ return true; }
 void AWTCPlayerState::setHealth_Implementation(int32 HP){ Health = HP; }




.h:

 public:
     AWTCPlayerState(const FObjectInitializer& ObjectInitializer);
 
     UPROPERTY(BlueprintReadWrite, Category = "Stats", EditAnywhere, Replicated)
         int32 Health;
     UFUNCTION(BlueprintCallable, Category = "Getters and Setters")
         int32 getHealth();
     UFUNCTION(BlueprintCallable, Reliable, Server, WithValidation, NetMulticast, Category = "Getters and Setters")
         void setHealth(int32 HP);
         virtual void setHealth_Implementation(int32 HP);
         virtual bool setHealth_Validate(int32 HP);

Product Version: UE 4.7
Tags:
more ▼

asked Jun 01 '15 at 01:34 AM in C++ Programming

avatar image

DrakeWalker
91 30 30 32

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

1 answer: sort voted first

NetMulticast is from server to client, and Server is from client to server, so you don't need both there. If you already use Server you cannot use BlueprintCallable, you need to make extra function with BlueprintCallable and just call the function setHealth.

more ▼

answered Jun 01 '15 at 01:50 AM

avatar image

Duncan Dam
3k 121 50 164

avatar image DrakeWalker Jun 01 '15 at 08:29 PM

Do i even need the: WTCPlayerState::setHealth_Implementation and validation functions? If so what am i supposed to put in them?

avatar image Duncan Dam Jun 02 '15 at 01:48 AM

yeah you need that, basically if setHealth is called in client, setHealth_Validate will validate the function, if you don't need to check anything just return true here coz return false will terminate the client connection to server. And then setHealth_implementation will be executed in server.

For any with BlueprintCallable, it will also create another setHealth_implementation in generated.h file, what you call in blueprint will be setHealth_implementation, cause this 2 is conflict you have to use server and blueprintcallable separately.

For my game, i normally put Server in front any server function like ServerSetHealth, then Blueprintcallable SetHealth just call ServerSetHealth.

avatar image DrakeWalker Jun 02 '15 at 08:31 PM

So, if in blueprint i want to set the health so that only the server can set health, I would have to do this?

 void AWTCPlayerState::setHealth(int32 HP){
     
     if (Role < ROLE_Authority) // Should this be '==' ?
     {
         ServersetHealth(HP);
     }
 }
 void AWTCPlayerState::ServersetHealth(int32 HP){} //This can be ignored correct?
 bool AWTCPlayerState::ServersetHealth_Validate(int32 HP){ return true; }
 void AWTCPlayerState::ServersetHealth_Implementation(int32 HP){ Health = HP; }
avatar image Duncan Dam Jun 03 '15 at 01:17 AM

Yeah correct, because you call ServersetHealth from client which Role < ROLE_Authority, and the implementation will be executed in server. If you put Role == ROLE_Authority and call ServersetHealth, the implementation will never be executed.

avatar image DrakeWalker Jun 03 '15 at 02:07 AM

I have setHealth set to Blueprint callable, but i still cant find or call it in blueprints.

avatar image Duncan Dam Jun 03 '15 at 02:49 AM

can you find getHealth ?

avatar image DrakeWalker Jun 03 '15 at 03:00 AM

No, i cant. When i creates the blueprint, i used the c++ class as the parent.

In the details or default tab in blueprints, i do see the value health, but i can't do anything with it

avatar image Duncan Dam Jun 03 '15 at 03:50 AM

strange, after add a new function do you rebuild solution or use build solution ?

avatar image DrakeWalker Jun 03 '15 at 10:19 AM

I compile the code using the button in the editor

avatar image Duncan Dam Jun 04 '15 at 01:18 AM

when you add new function, you need to close the editor, rebuild in visual studio then open editor again, hot reload only work when you change some code in function.

avatar image DrakeWalker Jun 05 '15 at 01:04 AM

Worked thanks! I only had to restart the editor the first time though.

(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