"Missing '*' in Expected a pointer type" with UFUNCTION?

Hi,

Can someone tell me why the following code compiles (UpdateType is an global enum and FYagPotentialStruct is a struct defined in another class):

//UFUNCTION(Server, WithValidation, Reliable)
	void ServerUpdatePotential(UpdateType Type, UYagFdP::FYagPotentialStruct *InStruct);

And why the following code gives me a “Missing ‘*’ in Expected a pointer type” error at compilation ?

UFUNCTION(Server, WithValidation, Reliable)
	void ServerUpdatePotential(UpdateType Type, UYagFdP::FYagPotentialStruct *InStruct);

(In the real code, i added the _Validate and _Implementation when UFUNCTION is active)

I’m a c++ beginner, so maybe i am doing something stupid or forbidden, but why would the same definition work without UFUNCTION and fail with it ?

Thanks

Cedric

I get the same error with “FYagPotentialStruct* InStruct”, “FYagPotentialStruct *InStruct”, and even when getting rid of the pointer “FYagPotentialStruct InStruct”

Not sure if UFUNCTION requires the * to be next to the c++ type declaration as in

UYagFdP::FYagPotentialStruct* InStruct

Which is the accepted new form vs the old c-style pointer declaration? Just a guess

i finally could come up with some workable code:

UFUNCTION(Server, WithValidation, Reliable)
	void ServerUpdatePotential(UpdateType Type, const FYagPotentialStruct InStruct);

changes:

  • the struct must be define outside the class
  • the pointer is forbidden (no problem here, it’s a read only access, i made it a const)

Just in case someone is interested, the pointer version:

UFUNCTION(Server, WithValidation, Reliable)
	void ServerUpdatePotential(UpdateType Type, const FYagPotentialStruct* InStruct);

gives this error:

Inappropriate ‘*’ on variable of type ‘FYagPotentialStruct’, cannot have an exposed pointer to this type.

oh well, one of those deep mysteries for me.

I can continue to work, i close the ticket.

structs defined by USTRUCT in UE4 cannot use the standard raw pointer, it’s an intended limitation. You can use a shared pointer (SharedPtr if I remember correctly) if you really need to pass a pointer instead of the value.

Instead of passing by pointer, you can pass by reference: const FYagPotentialStruct& InStruct. This still avoids the copy, but abides by the “no pointer” limitation of UStructs.