Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by IgorAherne · Aug 25, 2015 at 08:37 PM · sizescriptableobjecttreedatastructure

400 Scriptable objects per 1 datastructure = overkill. Halp plz

Hello everyone!


I have a kd-tree datastructure.

The leaf nodes are used to store items. Items hold: a vector position and 4 references to other similar items.

Kd-tree nodes are also referencing each other (parent-child relationship).


To keep those references, each node of my tree is a scriptable object and gets saved as an asset onto the disk.

The items the leaf nodes hold are also scriptable objects and are also saved as assets.


However, just to store 50 items like that, I need to create ~200 tree nodes (200 scriptable objects).

This comes down to about 400KB of size just for the tree. But I need to store information about 50 000 items, which would rocket up to Gigabytes of data.


So, creating a scriptable object to store information in 2 fields and keep a few references seems an overkill. 1 scriptable object =2-3kb of data.

.

..Please save me, what are my alternatives?

Comment
Add comment · Show 5
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 stepan-stulov · Aug 25, 2015 at 09:45 PM 0
Share

Is any one node of the tree referenced from more than one spot of the tree? If not, then you don't need true references which unity implements with scriptable objects. Simple classes marked as [Serializable] will do. Their serialization is embedded "in place". Sorry if the question is stupid, I'm not very familiar with kd trees.

avatar image IgorAherne · Aug 25, 2015 at 09:57 PM 0
Share

yep, every node holds a link to the parent node. The child node can have it's own children, which requires references as well :( Sort of like Linked List, but every element holds references to 2 elements at once, not 1 like a List does

avatar image IgorAherne · Aug 25, 2015 at 11:49 PM 0
Share

if you are interested about learning trees, you can check out my tutorial https://www.youtube.com/watch?v=TwZH-aoSzJk

avatar image stepan-stulov · Aug 26, 2015 at 09:09 AM 0
Share

No, my question was not whether one node references many, but whether any one node is referenced from more than one non-parent. That's almost exactly the reverse. But you've got your question answered anyway by @Baste. He replied exactly with what I've been trying to clarify but was faster:)

avatar image stepan-stulov · Aug 26, 2015 at 09:20 AM 0
Share

@IgorAherne Here is another thing to keep in $$anonymous$$d if you go for Unity's serialisation:

http://answers.unity3d.com/questions/434489/unitys-serialization-seems-to-have-a-maximum-depth.html

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by cjdev · Aug 25, 2015 at 10:16 PM

Since you don't have anything more in your objects than a reference to the parent I don't think you actually need to necessarily define them as scriptable objects. So long as you keep track of the parent and the Vector3 you're good right? I think you could use a tree if you create an index that accounts for which 'branch' on the tree the Vector3 resides like this:

alt text

And then you can get the parent just by using modulus on the index:

 private int GetParent(int child)
 {
     int numDigits = child.ToString().Length;
     return child % (int)Mathf.Pow(10, numDigits - 1);
 }

With this method you could store it all either in one dictionary with an int key (or long if you have a lot of children) and Vector3 values or split up the Vector3 into floats and create 4 arrays of fixed length, using corresponding indices to match up the values. Tough problem no matter how you go about it, good luck!


tree-diagram.png (34.2 kB)
Comment
Add comment · Show 1 · Share
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 IgorAherne · Aug 25, 2015 at 11:46 PM 0
Share

Thank you! This has turned me in the direction of storing all the information in dictionaries. This wouldn't be a problem with SerializationCallBackReciever.

The thing is, the tree is built once, - no insertion / delition is intended. So after its built, I can just traverse it and flush all data into a single dictionary. Values of such dictionary could be simple serializable classes (holding Vector3s and ids of other nodes in the same dictionary).

Because nodes also contain items which are also referencing other items, this might come down to several dictionaries with IDs everywhere. :D

I could then manipulate the ids to access the correct values in both dictionaries.

Thank you

avatar image
1

Answer by Baste · Aug 25, 2015 at 10:19 PM

Why does the nodes have to be scriptable objects?

You could implement the nodes as serializeable classes (or structs), and simply keep them in an array - ordered or unordered - in your tree scriptable object. Arrays of serializeable objects can be serialized, and that should seriously cut down on your disk space usage.

You could also store this information in your own format. Unity has a great built-in system for serializing stuff directly, without you having to write any code, but if you write your own format to read/write this data to files, you could cut the neccessary amount of data in the files by a lot. It'll take a bit of time, but might be worth it if you're storing very large amounts of information.

Comment
Add comment · Show 1 · Share
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 IgorAherne · Aug 25, 2015 at 11:12 PM 0
Share

Yep, currently thinking about binary serializer. The problem is that all the nodes have to hold references to each other, so xml serializer won't work. They also hold references to items. Items in tern also hold references between each other

Thank you for the answer!

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

27 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

Related Questions

Where I can change default brush size fo terrain editor? 1 Answer

Many scriptable objects at once = fine? 0 Answers

How to access TreeData 1 Answer

Are ScriptableObjects good for non-visualised models? 2 Answers

Tree Texture Altas Size 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