Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Slashscreen · Jan 28 at 02:18 AM · dotsblob

DOTS: Blob-compatible Dictionaries for use with YamlDotNet

I am making a kind of cellular automata experiment. Each type of block has its own YAML configuration file that is used to determine its behavior. Right now, I am deserializing each file as a blob asset, and storing a reference inside the entity. However, I am having trouble making a deserializable struct that will work with both Blobs and YamlDotNet, because of its use of dictionaries. The config file will not be changed once it is loaded into memory. What do I do here? My struct is the following:

 public class ParsedRawDeserializationStruct
 {
     public enum Types
     {
         Block,
         Creature,
         Fluid
     }
  
     public enum BodyParts
     {
         Arm
     }
     public struct ParsedRawData
     {
         public GeneralData General;
         public PropertiesData Properties;
         public BehaviorsData Behaviors;
         public NativeList<BodyParts> Anatomy;
     }
  
     public struct GeneralData
     {
         public FixedString32 id;
         public NativeHashMap<FixedString32, FixedString32> name;
         public NativeHashMap<FixedString32, FixedString32> desc;
         public FixedString32 texture;
         public Types type;
     }
  
     public struct PropertiesData
     {
         public NativeList<FixedString32> tokens;
         public int hardness;
         public NativeHashMap<FixedString32, int> species_stats;
         public NativeHashMap<FixedString32, int> lifecycle;
         public BlobPtr<UnsafeHashMap<FixedString32, int>> stats;
         public NativeList<FixedString32> custom_props;
     }
  
     public struct BehaviorsData
     {
         public NativeHashMap<FixedString32, NativeList<FixedString32>> behaviors;
     }
  
     public struct RawBlobStruct
     {
         public BlobArray<ParsedRawData> Arr;
     }
  
     public static BlobAssetReference<ParsedRawDeserializationStruct.RawBlobStruct> CreateRawBlobAsset(ParsedRawData data)
     {
         using var blobBuilder = new BlobBuilder(Allocator.Temp); //new builder
         ref var parsedRawBlobAsset = ref blobBuilder.ConstructRoot<RawBlobStruct>(); //create new asset
  
         var arrays = blobBuilder.Allocate<ParsedRawData>(ref parsedRawBlobAsset.Arr, 1);
         arrays[0] = new ParsedRawData();
  
         BlobAssetReference<ParsedRawDeserializationStruct.RawBlobStruct> blobAsset = blobBuilder.CreateBlobAssetReference<RawBlobStruct>(Allocator.Persistent); //create reference
         blobBuilder.Dispose();
         return blobAsset;
     }
 }

also while we're at it: how big is a BlobAssetReference in bytes? just curious.

Comment
Add comment · Show 4
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
avatar image andrew-lukasik · Jan 29 at 05:50 PM 0
Share

how big is a BlobAssetReference in bytes?

 unsafe
 {
     int size = sizeof(BlobAssetReference<ParsedRawDeserializationStruct.RawBlobStruct>);
     UnityEngine.Debug.Log($" size: {size} bytes");
 }

prints: size: 8 bytes

avatar image Slashscreen andrew-lukasik · Feb 01 at 04:16 AM 0
Share

ah ,thank you. I figured as much because I believed it to be a 64 bit pointer. A little larger than I would like, but I can make it work.

avatar image andrew-lukasik · Jan 29 at 06:52 PM 0
Share

General advice: don't mix Unity.Collections' types with blob assets. Choose either one of them.

Blobs are read-only so no dependencies to manage, which is convenient for all read-only types of data like this one.


System.Collections.Generic.Dictionary<T,K> is something you won't see anywhere close blob assets and Unity.Collections. If you need Blob-HashMap you can check how others implemented it already and copy study their code samples. Alternatively, you can store hashmap entries as BlobArray<KeyValuePair<T,K>> or BlobArray<T> keys and BlobArray<K> values to just run linear search if you can get away with it (low-overhead for short arrays only).

avatar image Slashscreen andrew-lukasik · Feb 01 at 04:15 AM 0
Share

Yeah, I know that I shouldn't be using collections, I just don't know another way around it for deserialization. Curious. I'm using the implementation here, https://github.com/bartofzo/BlobHashMaps , but I still get the error ConstructBlobWithRefTypeViolation: You may not build a type RawBlobStruct with Construct as RawBlobStruct.Arr[].General.name.data.values[] is a reference or pointer. Only non-reference types are allowed in Blobs. error...

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

174 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 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

How to make a blob shadow project from a fixed angle as the object rotates? 2 Answers

Exporting 3DS Max BlobMesh to Unity 1 Answer

How do I load/unload a SubScene in ECS? 1 Answer

What are Animation Channels? 0 Answers

Dots physics ComputePenetration equivalent 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