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"

Error with Macro NetMulticast at GENERATED_BODY()

I want to use UFUNCTION(NetMulticast, Reliable)

My goal: If i call Die() on the server i want that all clients call Die too, because all instances should die.

.h :

 virtual bool Die();
 
 UFUNCTION(NetMulticast, Reliable)
 void Client_Die();

.cpp :

 bool ATestCharacter::Die()
 {
     if (!CanDie())
     {
         return false;
     }
     // Die implementation here
     // ....
 
     // If we call die on the server, call die on all clients too
     if (HasAuthority())
     {
         Client_Die();
     }
     return true;
 }
 
 void ATestCharacter::Client_Die_Implementation()
 {
     Die();
 }


This all makes sense, but i get this error. The error disapears if i delete the "UFUNCTION(NetMulticast, Reliable)" line. And the error appears at the line with "GENERATED_BODY()". I dont know how to fix it.

 1>------ Build started: Project: ProjectArena, Configuration: Development_Editor x64 ------
 1>  Parsing headers for ProjectArenaEditor
 1>  Reflection code generated for ProjectArenaEditor
 1>  Performing 8 actions (4 in parallel)
 1>  DefaultAttributeSet.cpp
 1>  CharacterInputComponent.cpp
 1>  PlayerHUD.cpp
 1>  InventoryItem.cpp
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Public\ArenaCharacter.h(13): error C2059: syntax error : 'constant'
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Public\ArenaCharacter.h(13): error C2143: syntax error : missing ';' before ''template<''
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Public\ArenaCharacter.h(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Public\ArenaCharacter.h(13): error C4183: 'EMIT_CUSTOM_WARNING_AT_LINE': missing return type; assumed to be a member function returning 'int'
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Public\ArenaCharacter.h(13): error C2059: syntax error : 'constant'
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Public\ArenaCharacter.h(13): error C2143: syntax error : missing ';' before ''template<''
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Public\ArenaCharacter.h(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Public\ArenaCharacter.h(13): error C4183: 'EMIT_CUSTOM_WARNING_AT_LINE': missing return type; assumed to be a member function returning 'int'
 1>  ProjectArena.generated.cpp
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Public\ArenaCharacter.h(13): error C2059: syntax error : 'constant'
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Public\ArenaCharacter.h(13): error C2143: syntax error : missing ';' before ''template<''
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Public\ArenaCharacter.h(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Public\ArenaCharacter.h(13): error C4183: 'EMIT_CUSTOM_WARNING_AT_LINE': missing return type; assumed to be a member function returning 'int'
 1>  Agent1Controller.cpp
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Public\ArenaCharacter.h(13): error C2059: syntax error : 'constant'
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Public\ArenaCharacter.h(13): error C2143: syntax error : missing ';' before ''template<''
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Public\ArenaCharacter.h(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Public\ArenaCharacter.h(13): error C4183: 'EMIT_CUSTOM_WARNING_AT_LINE': missing return type; assumed to be a member function returning 'int'
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Private\CharacterInputComponent.cpp(59): error C3861: 'ServerSetIsMeleeAttacking': identifier not found
 1>  ArenaCharacter.cpp
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Public\ArenaCharacter.h(13): error C2059: syntax error : 'constant'
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Public\ArenaCharacter.h(13): error C2143: syntax error : missing ';' before ''template<''
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Public\ArenaCharacter.h(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Public\ArenaCharacter.h(13): error C4183: 'EMIT_CUSTOM_WARNING_AT_LINE': missing return type; assumed to be a member function returning 'int'
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Private\ArenaCharacter.cpp(198): error C2556: 'bool AArenaCharacter::Die(void)' : overloaded function differs only by return type from 'void AArenaCharacter::Die(void)'
 1>          D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Public\ArenaCharacter.h(101) : see declaration of 'AArenaCharacter::Die'
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Private\ArenaCharacter.cpp(198): error C2371: 'AArenaCharacter::Die' : redefinition; different basic types
 1>          D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Public\ArenaCharacter.h(101) : see declaration of 'AArenaCharacter::Die'
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Private\ArenaCharacter.cpp(210): error C3861: 'ClientDie': identifier not found
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Public\ArenaCharacter.h(13): error C2059: syntax error : 'constant'
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Public\ArenaCharacter.h(13): error C2143: syntax error : missing ';' before ''template<''
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Public\ArenaCharacter.h(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Public\ArenaCharacter.h(13): error C4183: 'EMIT_CUSTOM_WARNING_AT_LINE': missing return type; assumed to be a member function returning 'int'
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Public/ArenaCharacter.h(13): error C2059: syntax error : 'constant'
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Public/ArenaCharacter.h(13): error C2143: syntax error : missing ';' before ''template<''
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Public/ArenaCharacter.h(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
 1>D:\GameDev\UnrealProjects\ProjectArena\Source\ProjectArena\Public/ArenaCharacter.h(13): error C4183: 'EMIT_CUSTOM_WARNING_AT_LINE': missing return type; assumed to be a member function returning 'int'
 1>  -------- End Detailed Actions Stats -----------------------------------------------------------
 1>ERROR : UBT error : Failed to produce item: D:\GameDev\UnrealProjects\ProjectArena\Binaries\Win64\UE4Editor-ProjectArena.pdb
 1>  Total build time: 90,18 seconds
 1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets(38,5): error MSB3073: The command "D:\GitHub\UnrealEngine\Engine\Build\BatchFiles\Build.bat ProjectArenaEditor Win64 Development "D:\GameDev\UnrealProjects\ProjectArena\ProjectArena.uproject"" exited with code -1.
 ========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========



Product Version: Not Selected
Tags:
more ▼

asked Mar 21 '15 at 01:25 PM in C++ Programming

avatar image

Nhorth
80 8 11 12

avatar image Nhorth Mar 21 '15 at 10:48 PM

someone has an idea where to look for this error?

avatar image [AMG]Nate Mar 27 '15 at 04:59 PM

I am having the exact same issue with my code (which appears to be just as simple as yours). I've read many tutorials and Epic's own documentation but it appears to be a collision between the linker and UHT not doing it's job properly. Maybe there's a step we missed? Also: None of the code I added is for Blueprints or will be used by Blueprints. I'll be following this to see if anyone chimes in.

If I manually define the _Validation and _Implementation member functions the linker complains there are multiple definitions. This does make sense because they are created in the .generated header file but I must be missing or forgetting something.

avatar image Nhorth Mar 27 '15 at 08:08 PM

It works with the old deprecated GENERATED_UCLASS_BODY(), but not with the new GENERATED_BODY().

Good that im not the only one with the problem :) I really want to fix it.

I posted it into the error report section, but no one answered. https://answers.unrealengine.com/questions/197586/generated-body-and-ufunctionnetmulticast-reliable.html

avatar image Tim C ♦♦ STAFF Mar 31 '15 at 07:31 PM

Hi Wandêrer,

I tried adding the code you provided above to a character class using the GENERATED_BODY() macro, and was able to build it without any errors. I did have to modify the code slightly to get it to work (I don't have a CanDie() function, so I had to remove those lines from Die()).

.h

 virtual bool Die();
 
 UFUNCTION(NetMulticast, Reliable)
 void Client_Die();

.cpp

 bool ATestMulticastCharacter::Die()
 {
     if (HasAuthority())
     {
         Client_Die();
     }
 
     return true;
 }
 
 void ATestMulticastCharacter::Client_Die_Implementation()
 {
     Die();
 }

I added this code to the character class that is created in a new code project made using the First Person template, then built the project successfully in Visual Studio.

What version of the Engine are you using, and are you using the binary version installed by the Launcher or did you build the Engine from source code? I was using 4.7.3 built from source code.

avatar image [AMG]Nate Apr 01 '15 at 08:18 AM

Hi Tim,

Wandêrer and I are having the same issues. Much like you, I tried to create a simple function call with Implementation and get failed compiles for seemingly no reason. When the linker replaces GENERATED_BODY() with the appropriate generated code, it seems as though there's a conflict with the generated _Implementation and the actual _Implementation member function (it complains it's already defined but fails to compile if it's not there). I'm using 4.7.3.

Really confused here because it worked with other replicated actors I've defined. If it makes any difference, the function I'm having trouble with is in my Character class/header files.

Cheers, -Nate

avatar image Tim C ♦♦ STAFF Apr 01 '15 at 02:49 PM

Hi Nate,

Would it be possible to get the full code (both .h and .cpp files) for the class where you are seeing this error occur?

Tim

avatar image [AMG]Nate Apr 01 '15 at 03:02 PM

Hi Tim,

I'd love to but for some reason it's not submitting when I hit the "Comment" button :( Let me try something else.

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

2 answers: sort voted first

Hi Nate,

I was able to see some build errors when I used the code you provided (thanks for that), but they appear to be different from the ones that Wandêrer provided in their original post. I was getting error C2535 with the line virtual void ServerTestMessage_Implementation(); included in the header file, and LNK2005 and LNK1169 without that line. Are these the same errors that you were seeing?

I have submitted a report of the error messages that I saw (UE-13153). Let me know if you were seeing any different errors and I'll see if I can reproduce those as well.

Tim

more ▼

answered Apr 01 '15 at 08:40 PM

avatar image [AMG]Nate Apr 02 '15 at 08:18 AM

Hi Tim,

Oh this is good news and I'm glad you were able to reproduce it. Yes those are the exact same compile/link errors I'm getting. Oddly enough, if I create a new actor via the editor and then set it up for replication via C++ I have no issues with it. Confusing but maybe that indicates something else.

@Wandêrer Didn't mean to hijack your post. Sorry mate.

Cheers guys, -Nate

avatar image Tim C ♦♦ STAFF Apr 20 '15 at 09:33 PM

Hi Nate,

I just wanted to give you a quick update on this. The report that I had submitted based on the code you provided was sent back to me with a response that the function definition should be placed in the _Implementation, and not in the function itself.

In the sample code you provided, that means moving the code from void ASimpleNetworkGame_47Character::ServerTestMessage() into void ASimpleNetworkGame_47Character::ServerTestMessage_Implementation(). The Unreal Header Tool automatically creates the ServerTestMessage() function definition, so adding that definition to your .cpp file is what is creating the compile error.

To sum it up, the only definitions you need to add to your .cpp file are the ones for bool ASimpleNetworkGame_47Character::ServerTestMessage_Validate() and void ASimpleNetworkGame_47Character::ServerTestMessage_Implementation().

Tim

avatar image [AMG]Nate Apr 21 '15 at 09:00 AM

Hi Tim,

That makes sense. I had a play with it last night and discovered what you mentioned above :) Also, the patch you guys released yesterday seemed to fix a tonne of issues I had unrelated to my wonky code.

Cheers for the follow-up,

-Nate

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

Hi Tim, Here they are. I've omitted a bunch of the code form the first-person Shooter template for 4.7 so here goes:

.h

 #pragma once
 #include "GameFramework/Character.h"
 #include "UnrealNetwork.h"
 #include "SimpleNetworkGame_47Character.generated.h"
 
 class UInputComponent;
 
 UCLASS(config=Game)
 class ASimpleNetworkGame_47Character : public ACharacter
 {
     GENERATED_BODY()
 
     // Omitted code from first-person shooter template....
 
 public:
 
     // Omitted code from first-person shooter template....
 
     UFUNCTION(Server, Reliable, WithValidation)
     void ServerTestMessage();
     //virtual void ServerTestMessage_Implementation();    // Commented out due to linker issue.
 
 protected:
 
     // Omitted code from first-person shooter template....
 
 };

.cpp

 #include "SimpleNetworkGame_47.h"
 #include "SimpleNetworkGame_47Character.h"
 #include "SimpleNetworkGame_47Projectile.h"
 #include "Animation/AnimInstance.h"
 #include "GameFramework/InputSettings.h"
 
 DEFINE_LOG_CATEGORY_STATIC(LogFPChar, Warning, All);
 
 //////////////////////////////////////////////////////////////////////////
 // ASimpleNetworkGame_47Character
 
 ASimpleNetworkGame_47Character::ASimpleNetworkGame_47Character(const FObjectInitializer& ObjectInitializer)
     : Super(ObjectInitializer)
 {
         // Omitted code from first-person shooter template....
 
     bReplicates = true;
 }
 
         // Omitted code from first-person shooter template....
 
 void ASimpleNetworkGame_47Character::ServerTestMessage()
 {
     // If we're not a server (a client), call the server function.
     if(Role < ROLE_Authority)
     {
         if(GEngine)
         {
             GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Green, TEXT("Greetings from the ServerTestMessage function."));
         }
         ServerTestMessage();
     }
 }
 
 bool ASimpleNetworkGame_47Character::ServerTestMessage_Validate()
 {
     return true;
 }
 
 void ASimpleNetworkGame_47Character::ServerTestMessage_Implementation()
 {
     ServerTestMessage();
 }
more ▼

answered Apr 01 '15 at 03:04 PM

avatar image

[AMG]Nate
0 2 5

(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