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 Starleg2 · May 26, 2018 at 07:36 PM · arrayobjectclassjsonrevert

Cannot edit values of Class when created using .JSON file

Json File alt text Tile + Tile Loader Class alt text when using the editPoz function in tile Class it changes the value of the tile but when assigning that tile to an array of tiles it reverts back to the JSON defined X and Y

int tileType = Mathf.RoundToInt(map[xLocMap, yLocMap]); Tile tile = tiles[tileType]; tile.editPoz(j, i); print(tile.locXPoz + " " + tile.locYPoz); tilesInChunk[j + (i * size)] = tile;

tile.png (45.8 kB)
json.png (14.3 kB)
Comment
Add comment · Show 2
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 Tobychappell · May 26, 2018 at 07:46 PM 0
Share

$$anonymous$$ight need to see more code where you are perfor$$anonymous$$g this change. I cannot see why this would happen. Unless your indexes are not where you expect them to be, meaning that you are altering one tile and inspecting another.

avatar image Starleg2 · May 27, 2018 at 04:43 AM 0
Share

this is the chunk script that creates the tiles alt text

chunk.png (85.4 kB)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · May 27, 2018 at 12:36 AM

You seem to try to store instance information within a class that is only used / designed to describe tile types. You only have one "Tile" instance for every tile type but not for every actual tile. Your "map" seems to only hold the index of the tile type that the tile at the specified position has. You then use this ID to get that one single "Tile" instance for this type. So it's pointless to store any tile instance specific information in that class because you only have one "shared" instance for each type.


For example your second tile type is "Dirt" which has the index "1" inside your tiles List. So every tile inside your map that should be dirt will have an index of "1". So when querying the type from the map you get a value of 1 for each dirt tile. So every dirt tile will just reference the one "Tile" instance in your tiles List.


I'm not sure you really understand what you're doing here ^^. Just like in minecraft the actual terrain is just made up of blockIDs + some metadata. Each blockID corresponds to one particular block instance. The block class itself doesn't have a position since it describes just the type of block. The class may have methods that you call for the actual functionality. However you usually have to pass the actual block position into the method. For example see [the updateTick method][1] which looks like this:

 void updateTick(World world, int i, int j, int k, Random random) 

So you have to pass in the reference to the world as well as the x, y and z coordinates of the block that you want to run the tick on. The actual Block class doesn't know about any block positions. The point here is that for every voxel in the game you only store a single byte which is the index to the block type. You don't have an instance of the Block class for every block. That would be total overkill. A single chunk in MC consists of 65536 blocks (height 256, width/length 16). If an area of 16x16 chunks is loaded that are 16 million blocks. Since every block in the voxel grid is just a single byte we only need 16 MB of memory to store the whole blocks of all loaded chunks. Imagine you had a seperate class instance for every loaded block. A single class instance would have probably 100+ bytes. So it would require 1.6GB of memory. It also would take ages to create all those class instances. Instead MC stores just the blockID as well as an additional metadata byte which may be used for various things (on / off state, orientation, color variant, ...) depending on the block type. [1]: http://mcmodhelp.wikia.com/wiki/Block_Class

Comment
Add comment · 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

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

105 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

Related Questions

JSON missing arrays 1 Answer

array of objects 1 Answer

adding classes to arrays 2 Answers

What are GameTiles? 1 Answer

Instantiating objects from a class? (C#) 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