Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Uniblocks: cube-based infinite voxel terrain engine

Discussion in 'Assets and Asset Store' started by RawLionWorkshop, Feb 2, 2014.

  1. Kobaltic1

    Kobaltic1

    Joined:
    Jan 22, 2015
    Posts:
    183
    Is there a list of changes to 1.3?
     
  2. Mark Henderson

    Mark Henderson

    Joined:
    Oct 25, 2013
    Posts:
    41
    Is there any built in way to remove a saved world? I can't seem to find anything for that.

    *edit* specifically I want to clear the saved seed file, since that seems to not be cleared by ChunkDataFiles.clearSave()

    *edit2* So my actual problem is that Engine.WorldSeed is a static, and persisted even if the seed file was deleted. adding the below to Engine allowed me to actually get new random worlds with the same file name in a single play session:


    Code (CSharp):
    1.  
    2.     public static void ClearSave() {
    3.         ChunkDataFiles.ClearSave();
    4.         WorldSeed = 0;
    5.     }
     
    Last edited: Jun 12, 2015
  3. RawLionWorkshop

    RawLionWorkshop

    Joined:
    Jan 29, 2014
    Posts:
    206
    Thank you for the suggestion, that looks like a pretty useful extra feature. Just be careful about duplicate block names, because Uniblocks currently doesn't do any checks to prevent them, but they might cause some unexpected behavior in this case.


    I think this system would definitely improve performance, it's just a question of whether it's worth the development time and the increased complexity.

    Interestingly, according to my current tests, in the new chunk spawning system I'm
    working on it seems that whether you generate colliders or not doesn't really make much difference in loading speeds. That might be because of some Unity 5 changes, I'm not really sure, but it seems that generating colliders isn't necessarily the main bottleneck anymore.

    Still, I'll try to do some more testing and see if your idea would be feasible if I have the time. However, with the new loading system, you hopefully won't really need to worry about loading speeds anymore.
     
  4. RawLionWorkshop

    RawLionWorkshop

    Joined:
    Jan 29, 2014
    Posts:
    206
    You can find the change log in the UniblocksDocumentation folder ("changelog.txt"):


    I suppose the persisting seed static is an annoying unexpected behavior. Thank you for pointing it out, I'll try to do something about it in the next update. In the meantime, you just basically need to remember to clear the seed manually whenever you change to a different world at runtime (whether by changing to a different world name, or deleting the existing world data).
     
  5. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,314
    Hello,

    if you consider having colliders only near the Player, please think of possible problems for items and monsters etc which psyically are on the surface or in a cave and not nearby maybe... ;-)

    Since the unity 5.1 update I think it is a bit more stable. With high chunk spawn distance I still get game crashes, but less than before. With spawn distance with max 6 I do not get any.
    But there are around 17 Network warnings since the update. It would be great if they could be fixed in the next uniblocks update.

    Thanks and have a nice Weekend!

    Firlefanz
     
  6. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,314
    Hello,

    since the Update Unity 5.1 I do not see shadows anymore!

    Can anybody tell me if that's a General Problem with unity 5.1?
    I tried an older backup but also with 5.1 and there were no shadows too...

    Any idea how I can fix it or what could be a cause of that Problem?

    Thanks a lot,

    Firlefanz
     
  7. In-The-Fade

    In-The-Fade

    Joined:
    Jan 17, 2014
    Posts:
    6
    I wanted to use enums instead, but it seems very hard to create them at runtime compared to lists or dictionarys. Because I'm adding and removing a lot of different block types as I'm testing new ideas, its a pain having to edit the enum every time. I'll figure something better out eventually. Love uniblocks btw, really awesome package, so easy to use. Keep up the good work maap!
     
  8. RawLionWorkshop

    RawLionWorkshop

    Joined:
    Jan 29, 2014
    Posts:
    206
    You really shouldn't be getting any crashes, even with high chunk distance (just low FPS and long loading times). The default setting of 7 should be perfectly stable. Do you have any information you could share regarding the crashes? Any specific situations that trigger them, any error messages you can retrieve? And most importantly, do you get crashes even with a fresh project with fresh unmodified Uniblocks and default settings? If not, that would suggest there is something wrong with your specific setup.

    Thank you for the information about the network warnings - if I understood correctly, they are only happening in Unity 5.1, right? I don't currently have 5.1 installed so I can't check it at the moment, but I'll make sure to take a look at it later.


    As for the shadows problem it's most likely something unrelated to Uniblocks. The chunk meshes use the standard Unity mesh renderers and shaders, so they should just behave like any other mesh, but I'll check for any problems once I get 5.1 installed.



    Thank you for the kind words.
    I think your system is pretty good as it is. The duplicate names are a minor problem that could be easily solved by adding a duplicate name check at startup.
    I've actually considered adding this kind of system in officially, but for the next update I have so much work that still needs to be done, and I'd really like to release it as soon as possible, that it will probably have to wait until later (there is some extra stuff that would need to be done for an official version, like integrating it into the networking code, proper documentation, etc).
     
  9. KenneyNL

    KenneyNL

    Joined:
    Jun 16, 2015
    Posts:
    8
    Just purchased Uniblocks, quite impressed, loving it so far! Would it be possible to add blocks by code instead of adding prefabs and selecting them? I'd like to create a huge amount of blocks and I've got them all described in a CSV file, I got Unity to parse the CSV and the next step would be to make Uniblocks understand the blocks created by code.

    Any pointer how to do it?
     
  10. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,314
    Hello maap,

    the crashes appear when new landscape is populating (too fast too much the same time?).
    When I run a lot sometimes it happens, when I use my Portal to a totally new Position it happens 30%.
    When Setting chunk distance 6 it is less and none with running, when Setting to 8 even with running it crashes pretty often. I added some log warnings couldn't find the error until now. It is just crashing...

    The Network warnings only appear in unity 5.1.
    Got my oculus DK2 now working it is pretty cool. :)
    Got my lighting and shadow Problems fixed, was my fault.

    I want to add a new function: saving buildings or just an area to file to duplicate or put in random generated world at a random Position.
    public struct Building
    {
    string Name;
    string Creator;
    public ushort[,,] Blocks;
    }

    Is the idea okay to store it this way, when done building just let the creator pick two positions and store from start Position to endposition?
    When later adding it into the world, can I just insert it like now the tree from one edge to the other or is there something I Need to take care about?

    We are talking about small stuff 10x10x10 maybe but also very large stuff (there Needs to be a flatten landscape under it of course).

    Thanks a lot and have a nice day :)
     
  11. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,314
    PS: Or would it be better to have a List for each Voxel with Voxel and Position?

    Thanks!
     
  12. RawLionWorkshop

    RawLionWorkshop

    Joined:
    Jan 29, 2014
    Posts:
    206
    If you simply want to parse a file once, and you don't have to do it at runtime, you can use some of the code from BlockEditor. Have you code interact with the following functions:

    • CreateBlock() -> create a new block and automatically assign it the lowest free id number, and set SelectedBlock to be the newly created block.
    • You can now edit the properties of the newly created SelectedBlock's Voxel component.
    • UpdateBlock() -> save the SelectedBlock as a prefab, with the custom properties you set in the previous step.
    • Once the prefab is saved, you can loop back to CreateBlock() to add and edit the next block.
    • ApplyBlocks() -> send all the saved prefabs to the Engine. You only need to do this once after you're done adding/editing blocks.

    If you need to add blocks at runtime, you just have to update the Engine.Blocks static array. It stores references to GameObjects of all the blocks - by default, they are prefabs, but I think at runtime you could create "template" instances of custom blocks in the scene and use them too, as long as you don't delete them from the scene (I'm not sure if you can save prefabs at runtime, but if you can, it would probably be preferable).

    So basically you'd need to instantiate an empty voxel prefab, change its properties to whatever you need, then store it in Engine.Blocks. The index of the array should be the voxel's id number (you might need to resize the array to fit the new blocks).

    The Engine.Blocks array is initialized in Engine's Awake function, so you'd need to add blocks to it after that, when it's already initialized.

    Let me know if this doesn't work or if you need more information, I wrote this from memory without testing, so it's possible I've missed something.


    That generally shouldn't happen, it's possible that you have your chunk limits set too high, which would result in too many chunks trying to spawn at the same time...

    In any case, I'm rewriting the whole chunk spawning system to distribute the load better, so hopefully you won't be seeing any more crashes in the new version.
    (And by the way, sorry that it's taking so long, it's not an easy thing to do, still working on resolving a few annoying issues, but I think it will be worth the wait)

    I think a ushort array would be the better choice in this case.
    You can insert it similar to how the trees are placed, but you need to keep in mind that the SetVoxelSimple function doesn't let you place voxels outside of the chunk you call it on (it will throw an error). SetVoxel is slightly slower, but will set voxels correctly even if they are outside of the current chunk's range, so you'll probably want to use that instead.
     
  13. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,314
    Hello maap,

    a question and a problem about buildings / manually changed Areas:

    Just like the AddTree I added a new AddBuilding void:

    void AddBuilding (Globals.BuildingStruct building, int x, int y, int z)
    {
    building.Height = 30;
    building.Width = 30;
    building.Depth = 30;

    for (int i=0; i<building.Width; i++)
    {
    for (int j=0; j<building.Height; j++)
    {
    for (int k=0; k<building.Depth; k++)
    {
    //chunk.SetVoxel(x + i, y + j, z + k, building.Blocks [i, j, k], false);
    chunk.SetVoxel(x + i, y + j, z + k, 80, true);
    }
    }
    }
    }

    As you see I replaced my building with a 30x30x30 block. But I just see Kind of 10x8x4 block.
    I guess it is because of the chunks borders. Only a part of my building is drawn into the start trunk, the rest is missing?
    It is for both using False or True in SetVoxel call.

    Any advice how to do that? If you want to have it for a sample in the next Version, I would also give you my source for saving and loading a building, which is already working. :)

    A 2nd question:

    I would like to mark the selected area for saving the building from Point A to Point B.
    What would you advice? Add a huge blockto the Scene somehow or draw an additional transparent block for the selected area or got a better idea? Maybe also be useful later for terraforming selection / adding water maybe etc.

    Thanks a lot for your help and have a nice Weekend!

    Firlefanz
     
  14. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,314
    PS: I solved the 2nd Problem with a big transparent cube for my selection. Looks good and works well. :)
     
  15. Engin_yildiz

    Engin_yildiz

    Joined:
    May 10, 2013
    Posts:
    7
    Hello maap,
    the voxels (cubes) break with one hit all the same. I want to change hit number for different voxel. How can I do it!
    Thanks for your interest.
     
  16. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,314
    I had the same Problem, if I may give a hint:

    In DefaultVoxelEvents.cs the block is destroyed. You can use voxelInfo.GetVoxel() to get your block number there and Change some code, maybe put the destroy into a new OnMouseHold void and let some time pass before you destroy it...
     
  17. RawLionWorkshop

    RawLionWorkshop

    Joined:
    Jan 29, 2014
    Posts:
    206
    Hi, really sorry for the late reply.

    I'm guessing that you put this code inside the terrain generator script, right?
    If so, the reason this doesn't work as it should is because you're trying to set voxels in chunks that haven't been spawned yet. The terrain generator runs immediately after its chunk is spawned, but chunks are spawned one after another, not at the same time. So basically your code will run before the chunk it needs gets spawned.

    Unfortunately it seems that there isn't really an easy and reliable to fix this without redesigning your code. When doing any kind of terrain generation, you have to edit only the voxels in the current chunk, because you can't rely on other chunks being loaded yet. The tree generator for example checks whether a tree will fit fully inside the current chunk, and doesn't place it if it won't.

    You could wait until all the chunks are properly loaded, and then run your code on all of them, but that will still leave you with some chunks at the edges of the chunk range. Plus you would need to edit the ChunkManager to insert your code between the chunk spawning step and mesh generation step, which is rather messy, and the update would make this obsolete anyway(most of the ChunkManager script will be rewritten).

    You can also try to manually spawn all the chunks you need when editing the voxels. For example, by editing the Chunk.SetVoxel function so that it does a ChunkManager.SpawnChunk when the neighbor chunk it's looking for is null.
    However, this might cause an endless chain of new chunks being spawned, if you have the buildings being placed in every chunk, so it's not really a 100% reliable solution.

    There are some other more elaborate ways to get around this problem, but they would be too specific and complicated to fully describe here. But basically the thing you need to do is either limit the changes to the current chunk, or make sure that all the chunks you need to edit are actually loaded.

    There also might be some other simpler way I've missed, but I can't really think of anything right now. If I do come across a good solution to this problem, I'll let you know.


    Like the post above said, you should look into DefaultVoxelEvents. By default, the blocks are destroyed from the OnMouseDown function, but by moving some code around you can change it to OnMouseHold, then you can keep track of how long the player has been holding down the mouse button, and only destroy the block if some amount of time has passed.
     
  18. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,314
    Biotopia-BuildingError.jpg
    Hi maap,

    I redesigned my add building void now.

    The building is a 3 dim Array with block numbers.
    In my test code I always use only block no. 92 for testing, and try to add a 30x30x30 building.

    The following code should in my opinion work perfect I do not get the Problem with the new code:

    void AddBuilding (Globals.BuildingStruct building, int origX, int origY, int origZ, int x, int y, int z)
    {
    if (origX - Globals.AddBuildingPos.x >= 0 && origX - Globals.AddBuildingPos.x < building.Width
    && origY - Globals.AddBuildingPos.y >= 0 && origY - Globals.AddBuildingPos.y < building.Height
    && origZ - Globals.AddBuildingPos.z >= 0 && origZ - Globals.AddBuildingPos.z < building.Depth)
    {
    chunk.SetVoxelSimple (x, y, z, 92);
    bolBlockset = true;

    if (x == Engine.ChunkSideLength -1)
    {
    Vector3 pos = chunk.ChunkIndex.ToVector3(); //chunk.VoxelIndexToPosition(chunk.ChunkIndex);
    ChunkManager.SpawnChunk((int)pos.x +1, (int)pos.y,(int)pos.z);
    }
    else if (x == 0)
    {
    Vector3 pos = chunk.ChunkIndex.ToVector3(); //chunk.VoxelIndexToPosition(chunk.ChunkIndex);
    ChunkManager.SpawnChunk((int)pos.x - 1, (int)pos.y,(int)pos.z);
    }
    else if (y == Engine.ChunkSideLength -1)
    {
    Vector3 pos = chunk.ChunkIndex.ToVector3(); //chunk.VoxelIndexToPosition(chunk.ChunkIndex);
    ChunkManager.SpawnChunk((int)pos.x, (int)pos.y+1,(int)pos.z);
    }
    else if (y == 0)
    {
    Vector3 pos = chunk.ChunkIndex.ToVector3(); //chunk.VoxelIndexToPosition(chunk.ChunkIndex);
    ChunkManager.SpawnChunk((int)pos.x, (int)pos.y-1,(int)pos.z);
    }
    else if (z == Engine.ChunkSideLength -1)
    {
    Vector3 pos = chunk.ChunkIndex.ToVector3(); //chunk.VoxelIndexToPosition(chunk.ChunkIndex);
    ChunkManager.SpawnChunk((int)pos.x, (int)pos.y,(int)pos.z+1);
    }
    else if (z == 0)
    {
    Vector3 pos = chunk.ChunkIndex.ToVector3(); //chunk.VoxelIndexToPosition(chunk.ChunkIndex);
    ChunkManager.SpawnChunk((int)pos.x, (int)pos.y,(int)pos.z-1);
    }
    }


    The idea is to always set one block, I call it like add tree and use the original voxel coordinates origx to have the building at the target Position (Globals.AddBuildingPos) and whenever I get to a chunks borders I spawn the neighbor chunk there.

    In the Loop in terraingenerator I use it like this:

    bolBlockset = false;
    {
    AddBuilding (Globals.Building, (int)voxelPosOrig.x, (int)voxelPosOrig.y, (int)voxelPosOrig.z, x, y, z);
    }
    if (!bolBlockset)
    {
    ...all other blocks like before


    It seems to work for more chunks right now, but it always has a huge empty area inside, und under it a totally open hole. The results always look like in the Screen. Could you please give me an idea what is wrong or what I missed?

    Thanks a lot for your help and have a nice Weekend!

    Firlefanz

     
  19. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,314
    PS: Would it make the gameplay faster and smoother if voids like SpawnChunk or my own UpdateChunk (with Floating and growing and falling down blocks) are put into an own Thread or Task? Everybody has a multicore These days...

    Thanks :)
     
  20. RawLionWorkshop

    RawLionWorkshop

    Joined:
    Jan 29, 2014
    Posts:
    206
    The main problem here is that you're trying to add something that just really doesn't fit in the engine. By design, chunk generation happens locally in one chunk only, and chunks load one at a time (that's why the world is split into chunks in the first place). If you try to change it, you're essentially significantly modifying the core parts of the engine and things get really messy.

    The chunk loading system is actually pretty complicated, so there could be all kinds of different reasons why your code doesn't work, and I won't be able to tell what the problem is without spending a lot of time and effort on testing and debugging.

    So really, the answer here is: sorry, what you're trying to do is just not supported.

    I would recommend considering some alternative solutions:
    - place only the part of the building that fits inside the current chunk, and queue up the rest of the building to be placed when the required chunk is loaded
    - first load all the required chunks, then place the buildings
    - generate the buildings procedurally, on a per-voxel basis, like the rest of the terrain (difficult but also the cleanest and most reliable solution)

    By the way, I do have some plants to solve this by making chunks load automatically in a reliable way whenever you need them, but it probably won't be in the next update.


    All Unity functions must run in the main thread, so it's not possible for SpawnChunk. It can work for your UpdateChunk as long as it doesn't use any Unity functions. You could do block physics calculations and such in a separate thread, but the mesh updates would still have to be done in the main thread.
     
  21. Kane C Hart

    Kane C Hart

    Joined:
    Jun 29, 2013
    Posts:
    26
    This is brilliant. I sadly don't have the cash but I had really enjoyed checking the demo out and reading the entire thread. It looks like you are constantly updating it and providing support.

    Keep up the good work will keep an eye on this I can't wait for even just for fun messing around.
     
  22. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,314
    Hi maap,

    I am already only putting into the actual chunk that building parts, that belongs to it. I just removed that SpawnChunks stuff from my code now it seems to work pretty well (putting saved or cloned buildings into the landscape).

    Any idea when the next Version of Uniblocks is coming out? Will it include the mesh Rotation for custom meshes by 90° (with a block for each direction but only one mesh loaded for all 4) ?
    This is really important for me :)

    Thanks a lot!

    Firlefanz
     
  23. RawLionWorkshop

    RawLionWorkshop

    Joined:
    Jan 29, 2014
    Posts:
    206
    I'm glad it's working for you now, sorry that I wasn't able to provide more help.

    The mesh rotation will be included in the update, it's already implemented and working fine. As for when it's coming out, I know it's been a really long time, but then I am completely rewriting one of the most complicated parts of the engine, it's really not an easy thing to do.

    It is actually mostly done and working, and the performance is definitely a lot better now (mostly when loading chunks at high speeds - no more falling out of the world even when moving really fast!). I just have to do some final polish to make sure it's ready for release. If I had to give a specific time, I'd say a week, maybe two weeks. But please don't take it as a promise, it's just a reasonable estimate.


    Thank you for your interest.
    I know the price is a bit steep, but I think the quality of the product you're getting justifies it, and according to the feedback I've been getting, most users are happy with their purchase.

    I'm also worried that if the price was lower and more people bought the asset, I wouldn't have the time to deal with the increased demand for support. That's why I would rather sell fewer copies at a higher price.
     
  24. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,314
    Hi maap,

    thanks a lot for the info! :)

    I must say this is a great voxel Terrain engine and the Support is very good!

    Have a nice Weekend,

    Firlefanz
     
  25. Endzone

    Endzone

    Joined:
    Dec 18, 2014
    Posts:
    119
    Hey maap :) ..,
    Quick Question is their some way to get a block to constantly check for an update and if the update gets what its checking for and spawns a block right beside it is their a way to get that block beside it to basically do the same thing as the first block and continue checking for the update? [The update its checking for could potentially be a bool]
    i hope my question makes sence .. Thanks!!
     
  26. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,314
    Hi Endzone,

    is it ChunkManager.SpawningChunks maybe you are looking for?
    I think it tells is some chunk is spawning at this Moment.
     
  27. Endzone

    Endzone

    Joined:
    Dec 18, 2014
    Posts:
    119
    Hey thanks for the reply and no sorry im not sure that would work im essentially trying to create physics Eg.. sand physics but the way i have set it out is so that if the block below it = 0 [Air] then it will spawn another sand block but i need the next sand block to carry on updating so it can check to see if the block below it also = 0 but after the first update nothing happens the sand once placed will spawn the next block and then it will stop their ..
    - Thanks again hopefully we can figure out what to do :S
     
  28. RawLionWorkshop

    RawLionWorkshop

    Joined:
    Jan 29, 2014
    Posts:
    206
    There is no easy way to have an update function for an individual block (because the blocks aren't actual objects), but there is an easier solution. You can just do your check when any block is modified - for example, in the OnBlockPlace function in DefaultVoxelEvents, you check if the block below is empty, and in the OnBlockDestroy function you check if there is a block above that should fall down (because you just destroyed a block under it).

    You only need to do this check when a block is changed, because the result will always be the same for blocks that don't change.

    You can then move the falling block using Voxel.PlaceBlock, which will trigger the check again, so it will continue falling until it fails the check.
     
  29. Endzone

    Endzone

    Joined:
    Dec 18, 2014
    Posts:
    119
    Thank you so much :)
     
  30. Endzone

    Endzone

    Joined:
    Dec 18, 2014
    Posts:
    119
    I have just tryed to do the "physics" useing Voxel.PlaceBlock but for some reason everytime i run this peace of code unity just dies ... im not exactly sure what it is im doing wrong i have a feeling its something Extremely stupid that im doing wrong but i cant seem to figure it out :/

    Code (CSharp):
    1. //This is placed in the OnBlockPlace
    2. if ( voxelInfo.GetVoxelType ().VName == "sand"
    3.                     && voxelInfo.chunk.GetVoxel(indexBelow) == 0) {
    4.                     Voxel.PlaceBlock(voxelInfo, 11);
    5.             }
     
  31. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,314
    Hello maap,

    when removing a block I now want to spawn an item. I created a prefab for my item but I have a Problem to get the needed block-gameobject.

    I think every block exists as a prefab with Name from block_0 - block_XX.

    How do I get the gameobject from that block to spawn an item with that block?

    I tried the following:

    public GameObject spawnedObject;

    /// <summary>
    /// Adds the item on the start position for the given blockID
    /// </summary>
    /// <param name="positionStart">Position start.</param>
    /// <param name="blockID">Block I.</param>
    public void AddItem(Vector3 positionStart, int blockID)
    {
    //spawnedObject = GetComponent ("block_" + blockID).gameObject;
    //spawnedObject = (GameObject)Resources.Load ("block_" + blockID);
    spawnedObject = GameObject.Find ("block_" + blockID);
    if (spawnedObject != null)
    Instantiate(spawnedObject, positionStart, new Quaternion());
    }


    Any advice please? Thanks a lot!

    Firlefanz
     
  32. RawLionWorkshop

    RawLionWorkshop

    Joined:
    Jan 29, 2014
    Posts:
    206
    Seems like this would cause an infinite loop, since you're placing the block over and over again in the same place. If you want the block to fall down, you would need to place it below the current block (create a new VoxelInfo using the indexBelow).

    I'm not really sure if I understand what you're trying to do, but generally you shouldn't instantiate the block prefabs as GameObjects. They're only there to store the block information, they are not supposed to exist in the scene.

    In any case, to get the reference to the prefab, you can just use Engine.GetVoxelGameObject. This will return the block prefab for a given voxel id.
     
  33. RawLionWorkshop

    RawLionWorkshop

    Joined:
    Jan 29, 2014
    Posts:
    206
    Now for some news on the update - it should be out very soon, for now I have a demo to share:
    https://www.dropbox.com/s/3hden1mywxtrr0z/Uniblocks 1.4 demo.zip?dl=0

    The loading speed is now dynamically adjusted to load chunks as fast as possible while maintaining a steady framerate, so it will vary depending on the machine. That's why I'd appreciate if anyone could tell me how it runs on their machine.
    The player movement speed is increased in the demo, so that you can fly over terrain really fast. In theory, you shouldn't be able to outrun the loading of chunks anymore. The FPS should also stay at about 60 all the time.

    If you notice anything unusual, please let me know!
     
  34. In-The-Fade

    In-The-Fade

    Joined:
    Jan 17, 2014
    Posts:
    6
    Hi maap, demo runs great, never dropped below 55fps on my desktop, and its a pretty old machine with an intel core 2 duo and 8gb of ddr2 ram. Didn't drop below 60fps on my laptop. Great work on improving the performance, can't wait.
     
  35. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,314
    Hi maap,

    thanks for the reply I will test with Engine.GetVoxelGameObject to get the mesh somehow to add it to my item prefab (when digging blocks and cutting trees etc want to spawn an item with that mesh from that block)...

    The demo is running very fast, very well and spawning chunks / blocks is Ultra fast. Wanna have it :)
     
  36. RawLionWorkshop

    RawLionWorkshop

    Joined:
    Jan 29, 2014
    Posts:
    206
    Thank you guys for testing the demo, I really appreciate the feedback!

    Keep in mind that blocks without a custom mesh do not actually have any mesh stored anywhere. The cubes are built dynamically as part of the terrain, so if you want a cube mesh that looks like a block, you will need to create it yourself (it would probably be easiest to just import cubes with the correct textures/UV maps using a 3d modelling program, but you could also build the cubes or assign textures using custom mesh building code).

    For blocks that use a custom mesh, getting the mesh from block prefabs is easy, it's simply stored in the VMesh property.
     
  37. Endzone

    Endzone

    Joined:
    Dec 18, 2014
    Posts:
    119
    Heyy maap thanks for your reply before i will be sure to try it out, but just as feedback the Engine Demo It seems great i get a steady 60 FPS jumping around Loading Chuncks Rapidly :) where as in the Version we have now i get roughly 20 - 30 fps whilst loading chunks
    Specs -
    Intel I5 CPU
    14GB DDR3 Ram
    Nvidia gtx 770 Phantom 4GB GPU
     
  38. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,314
    Hi maap,

    my items are now working for both custom meshes and cube meshes. Works totally great with physics, for example if you cut a tree and it falls like blasted lego pieces of a tree :)

    Just one more Problem here: can you give me a hint, how do I get the material?

    In Voxel. VSubMesh is the index of the material, how do I get the material itself for me item?

    Thanks a lot. Hope the release of the update could be in this week? I got free time this week :)
     
  39. RawLionWorkshop

    RawLionWorkshop

    Joined:
    Jan 29, 2014
    Posts:
    206
    Thank you for testing, glad to hear it's working well!

    The material is assigned to the Chunk prefab's MeshRenderer component, so you can get it using this on the Chunk prefab:
    Code (CSharp):
    1. GetComponent<Renderer>().materials[i];
    (i is the VSubmeshIndex)

    The update should be done this week. Maybe. No promises though, sorry!
     
  40. RawLionWorkshop

    RawLionWorkshop

    Joined:
    Jan 29, 2014
    Posts:
    206
    The 1.4 update is finally done!
    It should be available on the asset store within a few days. If you'd like to get it earlier, you can send me your invoice number (via PM or rawlionworkshop@mail.com), and I'll send you a download link.

    Changelog:
     
    nuonical likes this.
  41. Endzone

    Endzone

    Joined:
    Dec 18, 2014
    Posts:
    119
    Hey maap just a quick Question .. i Made a custom Flower model / mesh for my game all is good got it working but for some weird reason the model sits half a block above ground level.... ive tryed to fix it my self but had no luck.. any ideas on what could be the problem ? - Thanks Untitled-1.fw.png
     
  42. RawLionWorkshop

    RawLionWorkshop

    Joined:
    Jan 29, 2014
    Posts:
    206
    You can just move the model down in whatever program you used to model it. Simply select all the vertices and move them down half a unit. The center (pivot point) of the object should be in the middle of the block, so in your case probably above the flower.
     
  43. In-The-Fade

    In-The-Fade

    Joined:
    Jan 17, 2014
    Posts:
    6
    Hi maap, I've come across an error in the 1.4 version of Uniblocks. The error is "failed setting triangles, submesh index is out of bounds", the error points to this part of the ChunkMeshCreator script, inside the UpdateMesh method
    Code (CSharp):
    1. for (int i=0; i<Faces.Count; ++i)
    2. {
    3.     mesh.SetTriangles(Faces[i].ToArray(),i);
    4. }
    The error happens when you break a block, but only inside the first few chunks that spawn around the player. I thought it was a problem with one of my own scripts, but I tried it on a blank project with just Uniblocks and it still happens, just less frequently. Sometimes it causes other chunks to stop spawning, other times it continues with no problems.
     
  44. Endzone

    Endzone

    Joined:
    Dec 18, 2014
    Posts:
    119
    OHHH i see wow i did this before i made a post but i guess i didnt move it enough at all because it made almost no difference ... Thanks Alot got it working now :)

    Also ive ran into another weird problem for some reason any Transparent item i make the colliders also Generate with it ? i have only had this problem since i updated to unity5 .. .. i have gone into the chunk prefabs and changed the "Chunk Trigger Collider's" mesh collider and i set it to convex and then changed it to is trigger that seemed to make them no longer solid but now the selection of the transparent block is all weird and only actually selects sometimes because its now convex ... is their anyway around this or evan an alternate fix to this :S ? Thanks again for your help!
     
  45. RawLionWorkshop

    RawLionWorkshop

    Joined:
    Jan 29, 2014
    Posts:
    206
    This seems to be a problem with script execution order. I thought I fixed it, turns out not quite...

    Fortunately the fix seems to be pretty simple, just make sure that the Start function of the ChunkMeshCreator script doesn't actually execute on Start - so just rename it to something else (for example, Initialize). You'll also need to change the Start() function call at the beginning of RebuildMesh to point to the renamed function.

    This seems to fix the problem for me, but let me know if something still doesn't work!

    By the way, the fix will be included in the official release.

    Sounds like you're still using the old version of Uniblocks. Unity 5 unfortunately breaks trigger colliders. The 1.3 version of Uniblocks uses a different method for handling the collisions, so please get the update!
     
  46. Endzone

    Endzone

    Joined:
    Dec 18, 2014
    Posts:
    119
    Ohh i see ok cool Thanks :)
     
  47. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,314
    Hello,

    if anybody is interested, here is a uncommented Video Clip of my current game project using uniblocks:

    https://youtu.be/IM5TgLQfoJw

    Have a nice Weekend! :)
     
    nuonical likes this.
  48. In-The-Fade

    In-The-Fade

    Joined:
    Jan 17, 2014
    Posts:
    6
    This seems to work thanks. I have another quick question. Is this the correct way to get a chunk and voxel from a certain position:
    Code (CSharp):
    1. Chunk chunk = Engine.PositionToChunk(transform.position).GetComponent<Chunk>();
    2. voxelType = chunk.GetVoxelSimple(voxelInfo.index.x, voxelInfo.index.y, voxelInfo.index.z);
    Sometimes this works, but most of the time voxelType is 0. The full script is here http://pastebin.com/YpLd41i1 in case anything isn't clear, and this is where it gets called from another script:
    Code (CSharp):
    1. public override void OnBlockDestroy(VoxelInfo voxelInfo)
    2. {
    3.     GameObject dropItemPrefabInstance = Instantiate(dropItemPrefab, Engine.VoxelInfoToPosition(voxelInfo), Quaternion.identity) as GameObject;
    4.     dropItemPrefabInstance.GetComponent<DroppedItemMesh>().Create(voxelInfo);
    5. }
     
  49. RawLionWorkshop

    RawLionWorkshop

    Joined:
    Jan 29, 2014
    Posts:
    206
    Well, if you already have a VoxelInfo at the position that you want to check (since you're using the index of the voxelInfo, that seems to be the case), you can just get the voxel directly:
    Code (CSharp):
    1. voxelInfo.GetVoxel();
    Otherwise, to get a voxel from a world position, the best way is to use this:
    Code (CSharp):
    1. Engine.PositionToVoxelInfo (transform.position).GetVoxel();
    Your example doesn't work some of the time most likely because GetVoxelSimple only works inside one chunk, it won't work properly if you use it with an index that falls outside of the chunk's borders. In this case you'd want to use GetVoxel instead. It will get the voxel correctly even if it's outside of the current chunk.



    Thank you for sharing, it's always cool to see what people can do with the asset!
     
    nuonical likes this.
  50. Endzone

    Endzone

    Joined:
    Dec 18, 2014
    Posts:
    119
    Hello maap.... i have asked this question Before im Afrade im asking it again :( ..... i honestly have no idea how to get basic "sand physics" i have been trying to do this for Wayy too long now evan after your help last time i asked i still had no idea and still had many issues ... litterally all im trying to do is check to see if a block below the "sand" that is placed, is air then spawn another sand block delete the original sand block and then do that update check again ... i tryed using Voxel.PlaceBlock like you suggested but no matter what i did or how i placed that piece of code i either crashed unity or it simply didnt work ....
    i hate to ask but i have spent way too many frustrating hours on this.... is their some way you could Please throw together just an Extremely basic Version of what im asking ? if you could that would make my day :D