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"

TEnumAsByte saving and loading

Kind of a newbie question, but I've been working on this plug-in for saving and loading texture presets. I've gotten to a point where I can save out and load back in most of the values from a texture editor window, but I am having issues with the TEnumAsBytes.

I'm saving out the values like this:

 TEnumAsByte< enum TextureCompressionSettings >  compressionSettings = texture->CompressionSettings;

Then convert it to an FString using GetValue()

 "compressionSettings = " + compressionSettings.GetValue() + "\n"

I'm not sure if that's working as intended, and then the second problem is loading it back in. Loading it in from a file, the value would be loaded into an FString. How do I convert that to a value I can use to set TEnumAsByte with?

Product Version: UE 4.9
Tags:
more ▼

asked Nov 08 '15 at 07:38 PM in C++ Programming

avatar image

Spectral Ink
224 10 15 23

avatar image Spectral Ink Nov 16 '15 at 05:50 PM

wanted to ping this again, as I'm still not solving this problem. I can save out and load in all the other attributes of the texture class, but the ones that are TEnumAsByte. For some reason those are proving to be problematic. Any help would be appreciated.

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

2 answers: sort voted first

I thought I had answered this, but you were half right Jerry. I got the value correctly using your method

 uint8 mipGenSettings = (uint8)texture->MipGenSettings;

But in order to use that info to set the TEnumAsByte, I had to use the value to create a new enum. The set function required another enum.

 TEnumAsByte< enum TextureMipGenSettings > temp(FCString::Atoi(*value));
 texture->MipGenSettings = temp;

more ▼

answered Dec 05 '15 at 07:19 PM

avatar image

Spectral Ink
224 10 15 23

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

From one noob to another, I can provide the method I used to get this done:

 Common.h
 
     UENUM(BlueprintType)
     enum class Achievement : uint8
     {
         Achievement1        UMETA(DisplayName = "Achievement One"),
         Achievement2        UMETA(DisplayName = "Achievement Two"),
         Achievement3        UMETA(DisplayName = "Achievement Three"),
         Achievement4        UMETA(DisplayName = "Achievement Four")
     };
 
 
 .h
 
 UCLASS()
 class MYAPP_API UMyScore : public UObject
 {
     GENERATED_BODY()
 
 private:
 
     FText levelName;
 
     UPROPERTY()
     TArray<Achievement> achievements;
 
 public:
 
     friend FArchive& operator<<(FArchive& ar, UMyScore& data)
     {
         ar << data.levelName;
 
         if (ar.IsSaving())
         {
             int32 achievementCount = data.achievements.Num();
             ar << achievementCount;
 
             for (int32 x = 0; x < achievementCount; x++)
             {
                 uint8 val = (uint8)data.achievements[x];
                 ar << val;
             }
         }
         else
         {
             int32 achievementCount;
             ar << achievementCount;
 
             for (int32 x = 0; x < achievementCount; x++)
             {
                 uint8 val;
                 ar << val;
                 data.achievements.Add((Achievement)val);
             }
         }
 
         return ar;
     }
 
more ▼

answered Nov 16 '15 at 08:43 PM

avatar image

Jerry.Richards
168 9 17 30

avatar image Spectral Ink Nov 16 '15 at 10:56 PM

Thanks for that, but I'm not seeing how that helps me. UTexture2D is a Unreal object class that has TEnumAsByte variables as part of its class, I need to figure out how to get that data and write back to it so I can use that class.

I did find this example -

https://forums.unrealengine.com/archive/index.php/t-33140.html

 // Create the texture we're going to fill with data.
 UTexture2D* Tex2D = UTexture2D::CreateTransient(Width, Height, PF_B8G8R8A8);
 
 #endif // WITH_EDITORONLY_DATA
 Tex2D->PlatformData->NumSlices = 1;
 Tex2D->NeverStream = true;
 Tex2D->Rename(*FileName);
 Tex2D->CompressionSettings = TC_Default;

So setting it shouldn't be difficult if I can replace TC_Default with an FString. Then I need to figure out why I'm getting nothing when I call

 "compressionSettings = " + compressionSettings.GetValue() + "\n"

avatar image Jerry.Richards Nov 17 '15 at 01:00 AM

Reading and Writing the enum:

 if (ar.IsSaving())
 {
     uint8 val = (uint8)data.CompressionSettings;
     ar << val;
 }
 else
 {
     uint8 val;
     ar << val;
     data.CompressionSettings = val;
 }

That's assuming CompressionSettings is an enum.

avatar image Spectral Ink Nov 17 '15 at 01:04 AM

I can try that. Again, compressionSettings is a TEnumAsByte, but I'll give it a go and let you know what happens.

(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