Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by pablolopez280797 · Oct 31, 2020 at 04:43 PM · serializationscriptableobjectsplatmaps

How can I save splatmaps (alphamaps) in a Scriptable Object?

Hello everyone! I'm trying to save the 3 dimensional float array returned by the "GetAlphamaps (...)" function of the terrain data to a Scriptable Object in a variable of the same type. When I hit the save button in the script I have the save function, apparently this 3-dimensional array is saved in the scriptableobject it creates and saved in the folder of my choice. But when I press the Play button, and I stop the execution again. The 3-dimensional array acquires the value of null. I have read some articles and posts related to this topic and the reason seems to be that multidimensional arrays (among other types of variables) cannot be serialized by Unity and therefore their value becomes null in this case. But I would like to know if there is any article, video, post, method or class that I do not know and have not found to be able to save this array in an optimal way? I am attaching the code fragments of the scripts that are related to the creation and saving of the ScriptableObject, so that you know better what I am trying to do.

I call from a editor Script:

 if (GUILayout.Button("Save Splatmaps", GUILayout.Width(currentWidth / 3)))
 {
     SplatmapSerializedData serializedSplatmaps = myTarget.SaveSplatmaps();
     if (previousPath == string.Empty)
     previousPath = "Assets/";
     string path = EditorUtility.SaveFilePanel("Save Splatmap Data Asset", previousPath, myTarget.name + "_SplatmapData", "asset");
     if (string.IsNullOrEmpty(path)) return;
     previousPath = path;
     path = FileUtil.GetProjectRelativePath(path);
     TYLER_SplatmapData splatmapData = ScriptableObject.CreateInstance<TYLER_SplatmapData>();
     splatmapData.splatMapdata = serializedSplatmaps;
  
     AssetDatabase.CreateAsset(splatmapData, path);
     AssetDatabase.SaveAssets();
     AssetDatabase.Refresh();
     myTarget.LoadSplatmapData = splatmapData;
 }</code>

And the method SaveSpaltmaps():

 public SplatmapSerializedData SaveSplatmaps()
 {
     if (Tiles == null || (Tiles.GetLength(0) != terrainXSize || Tiles.GetLength(1) != terrainZSize)) Tiles = GetTyles();
  
     SplatmapSerializedData serializedSplatmaps = new SplatmapSerializedData();
     serializedSplatmaps.splatmaps = new SerializedSplatmap[Tiles.Length];
  
     int cont = 0;
     for (int x = 0; x < Tiles.GetLength(0); x++)
     {
         for (int y = 0; y < Tiles.GetLength(1); y++)
         {
             Texture2D[] alphamaps = new Texture2D[Tiles[x, y].OriginalTileTerrainData.alphamapTextures.Length];
             for (int i = 0; i < Tiles[x, y].OriginalTileTerrainData.alphamapTextures.Length; i++)
             {
                 alphamaps[i] = Instantiate<Texture2D>(Tiles[x, y].OriginalTileTerrainData.alphamapTextures[i]);
                 alphamaps[i].name.Replace("(Clone)", "");
             }
             serializedSplatmaps.splatmaps[cont] = new SerializedSplatmap(new Vector2Int(x, y), Tiles[x, y].OriginalTileTerrainData.alphamapResolution, alphamaps);
             cont++;
         }
     }
     return serializedSplatmaps;
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

146 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Saving players progress in ScriptableObject asset 1 Answer

Field is member of a type which is serializable but is of type which is not serializable 0 Answers

Make the same serialized class as a ScriptableObject? 1 Answer

Serializable types for ScriptableObject 2 Answers

Scriptableobject not saving if i force close the application. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges