Can I have UStructs with the same name in diferent files?

Im trying to create a pluggin to enable messaging trading between diferent machines using the MessageBus.
I had the server part done, it compiled correctly but once I tried to compile with the client part the following compiler error ocurred: “error : struct: ‘Message’ conflicts with class name”.
In both classes (server and client) I need a struct with the message to be sent, I simply copied and pasted the UStruct from the server to the client as the name has to be the same so it can be recognized by both endpoints.

struct FMessage

	int32 Message;

	FMessage() = default;

	FMessage(const int32& Msg) : Message(Msg) {}

this is my file structure, Client is client, Remote is server. In both of the .h files I have one UStruct as the one I refered.


Thank you for the attention.

No, UStruct names must be unique.

We typically define the structs for MessageBus events in their own header and then include it on both the sending and receiving side.

So you are telling me ot crate a new header (FMessageHeader) only for the struct? I tried that but had some errors still. I must include the header in both server and client .h files right? what about the FMessageHeader file, what should I include there? TapPlugin.h? any other weird dependency?

Yeah, that sort of thing.

If you take a look at WidgetSnapshotMessages.h (in Engine\Source\Developer\SlateReflector\Private) you can see the MessageBus events header used by FWidgetSnapshotService. In this case both the sending and receiving is handled by the same class, but we could just include WidgetSnapshotMessages.h anywhere that we needed access to those event types.

Splitting common types off into their own header (rather than copying types) is the standard way to share types between files in C/C++.