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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Using FOnlineJsonSerializable on a struct

Hello,

I'm trying to serialize a very simple struct, but I'm guessing UE4's preproccessor scripts are borking this.

My struct:

 USTRUCT(BlueprintType)
 struct FInventoryItemEntry : public FOnlineJsonSerializable
 {
     GENERATED_USTRUCT_BODY()
 
     UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Inventory")
     FString ItemId;
 
     UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Inventory")
     int32 Quantity;
 
     FInventoryItemEntry() { }
     FInventoryItemEntry(FString id)
     {
         ItemId = id;
         Quantity = 1;
     }
     FInventoryItemEntry(FString id, int32 count)
     {
         ItemId = id;
         Quantity = count;
     }
 
     BEGIN_ONLINE_JSON_SERIALIZER_FLAT
         ONLINE_JSON_SERIALIZE("ItemId", ItemId);
         ONLINE_JSON_SERIALIZE("Quantity", Quantity);
     END_ONLINE_JSON_SERIALIZER_FLAT
 };

My compilation error:

 Inventory.h(59): error : In Inventory: 'struct': Can't find struct 'FOnlineJsonSerializable'

Just below this struct I have a class that extends FOnlineJsonSerializable, and that compiles just fine, so it definitely has a reference to FOnlineJsonSerializable, I'm guessing this is a bug with the preprocessors.

Has anyone seen this or found a workaround? This is currently blocking me, and I'd rather not have to write a custom serializer method.

Thanks for any help!

Product Version: Not Selected
Tags:
more ▼

asked Apr 11 '15 at 12:50 AM in C++ Programming

avatar image

phil.harlow
0 3 4

avatar image phil.harlow Apr 13 '15 at 06:01 PM

Bumping...

avatar image phil.harlow Apr 13 '15 at 11:29 PM

Hello? Epic?

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

2 answers: sort voted first

Yay for Epic's wonderful support. Just switched to using a UObject instead. Yucky, wasteful hack for what we need, but quicker than waiting for a reply.

more ▼

answered Apr 22 '15 at 11:50 PM

avatar image

phil.harlow
0 3 4

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

This is an old question now, but I ran into this issue and found the problem and an alternate solution. The issue is that the type is not a USTRUCT, and so attempting to make a new USTRUCT that inherits from it will confuse the preprocessor.

TL;DR: It can't find the struct because it hasn't preprocessed it.

If you absolutely need the type to take advantage of the preprocessor (eg. make it exposed to Blueprint), you can make it a UObject inheriting class. Eg.

 UCLASS(BlueprintType)
 class UMyJsonSerializable : public FOnlineJsonSerializable, public UObject

But if you don't need your type to take advantage of the preprocessor, just making it a regular old struct will do the job. Eg.

 struct FMyJsonSerializable : public FOnlineJsonSerializable

You can still use it as you would any other C++ struct, because that's exactly what it is. You don't even have to use the prefix if you don't want to, the preprocessor won't enforce it.

Hope this helps someone, happy coding.

more ▼

answered May 18 '16 at 06:15 PM

avatar image

Grimeh
43 7 8 13

(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