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
0
Question by DanickCyb · Dec 28, 2016 at 12:23 AM · filemethodstreaming

how to get the Id stored at x,y,z in a file

Hello ! I have been working on it for a while and I just cant find an efficient way to make my script working basically, im storing ID of tile at a postion X,Y,Z in a file. I want the player to load all the ID close to him, and the only way Ive found is to iterate trough all the tile in the file and then I check if its close enough to the player to be spawned. This way worked well for me when my map has only a few tile... but when I made a desert of 1000x1000 tile) it was one million of tiles to iterate trough, and was very very laggy, was playing at 1 or 2 fps... The position of the player is known, so im searching a way to directly return the id of the tile at position x,y,z . The tile are all sorted, so I don't want a sorting algorithm :P I really need a method to directly refer to the node of my file Thx for helping me!

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 AlwaysSunny · Dec 28, 2016 at 12:23 AM 0
Share

Definitely time to look into a "chunk" approach to data management: Separating data into logical chunks, then only loading those chunks you currently need.

I think to get a more specific answer, you'll have to explain what kind of file you're working with, and what types of data you're storing in those files.

avatar image DanickCyb · Dec 28, 2016 at 12:51 AM 0
Share

well, im using a map editor, that store (X - 32 bits , Y - 8 bits Z - 32 bits and ID of the tile : 32 bits)
for each tile that I add, it store the data like this. Ive made a structure and I can refer to these data. I do not need the chunk approach, cause it will still result in the same issue, ill have to do a for loop trough all the chunk to find out which chunk to spawn and then spawn do a for loop in the chunk to find out which tile in the chunk to spawn... I need another method to directly get the id stored at tile x= 1004, y 0 and z 1040) as an example..... Is there a solution to it?

avatar image AlwaysSunny DanickCyb · Dec 28, 2016 at 12:54 AM 0
Share

Remember to post comments as comments and not as answers. This has been converted on your behalf.

I'm having difficulty understanding your situation. What kind of file are we talking about? Literally what is the file extension of the file?

I would strongly encourage you to contact the original author of the map editor you're using. It's rather unlikely that our volunteers will be familiar with the inner workings of third-party assets.

avatar image DanickCyb AlwaysSunny · Dec 28, 2016 at 01:23 AM 0
Share

I did the map editor :P its just a simple script that save a position and an ID. the file has currently no extension, its only a binary file, I also made a script that generate an xml file, but I don't use it anymore, In unity I got 2 Csharp script that can read both type of file actually, I can explain my problem better, imagine you've got a big bitmap file, and you want to check the pixel at a defined position x and y, how would you simply return only the color of the pixel without iterating trough all the file? its hard for me to explain better....

1 Reply

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

Answer by ElijahShadbolt · Dec 28, 2016 at 07:10 AM

I hope your x, y, and z are integers; floats muddy the waters a lot. If the data in the file is sorted (eg by X, then by Z, then by Y), you could use an efficient Search algorithm (eg binary search, but something more efficient) to locate the specific tile in a much shorter time than a linear search (foreach).

As @AlwaysSunny was saying, a chunk system would work beautifully in this situation. You would load only the few tiles that are directly nearest to the player (within a radius of, say, 3 tiles), then loop through those to find the closest tile. Then when the player moves to a different tile, load new tiles around that tile and unload the tiles that are farthest away. This means you only have to loop through something like 30 tiles at any one time, instead of all 1,000,000.

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 DanickCyb · Dec 29, 2016 at 01:07 AM 0
Share

Hello :) thx for the answer, I might resign myself to use the chunk approach even though I do not like it because I do not find any other solution, I have heard that dictionaries could be use with more than 1 arguments , that mean I could have a definition for each tile, but I doubt it will be fast enough ... !

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

6 People are following this question.

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

Related Questions

How to write files to the streaming asset folder in Android at runtime 1 Answer

Writing binary files on Android 1 Answer

do something if a method cant be executed 1 Answer

WEB game how in the dozens of songs quickly switch? There is a good way to do 1 Answer

Web radio playing inside unity? 2 Answers


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