Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Dynamic Batching on Instantiated Objects

Discussion in 'General Discussion' started by jamesjsewell, Jan 15, 2015.

  1. jamesjsewell

    jamesjsewell

    Joined:
    Jan 15, 2015
    Posts:
    5
    If I were to create a 3d survival game for android, which had a shelter building mechanic that allows you to place logs in the world, would it be possible to achieve using dynamic batching?

    there is the potential to have hundreds/thousands of logs in the world, if I were to batch them all together, do you think it would be a realistic goal? or would the sheer amount of objects nullify the batching, I'm not quite sure and I'd love to hear your input
     
  2. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    Prototype it. Put hundreds or thousands of batchable objects in a scene and run it on a device.

    You'll most likely need some form of LOD solution as well.
     
  3. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,071
    Do you need them loaded into memory at all times? You would probably get better results saving their position to a file or database and loading or unloading them based on whether or not they are within any loaded sections of the world.
     
    Last edited: Jan 16, 2015
  4. kburkhart84

    kburkhart84

    Joined:
    Apr 28, 2012
    Posts:
    910
    I agree with Ryiah. In general, the big open world type games never have much of the world loaded, rather only what is around you, and what is where you are likely going, either based on movement or the game itself. The rest is kept on the hard drive, ready to load when needed, while once you are in a new zone and don't appear to be returning, the old zone can get saved to a hard drive file.

    Remember that though writing/reading files from the hard drive tends to be slow, there are ways to get around this. For example, use binary file types when possible as opposed to text files. You can store more information in less space(as long as it is numbers, not actual text). Also, you would want to load or save the whole thing to/from a single buffer in one operation, which is much quicker than parsing a text file until end of line, then doing it again, etc... Then once that whole buffer is in memory, you can work with it very quickly to pull out where the logs are in the zone you are loading.
     
  5. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    Assuming that there's a small number of unique logs then at minimum only their position and orientation needs to be stored. For only "thousands" it's quite possible that the built in scene and culling systems will handle it just fine, so that's where I'd start.

    If that did turn out to be too slow I very much doubt that I'd go so far as streaming them to and from disk. In - you could store tens of thousands of log locations in just a few megs of RAM in the event that you had to write your own log culling/pooling system, so why get permanent (slow) storage involved for anything other than persistence between sessions?

    In any case, I suspect that you'll run into problems (solvable ones) elsewhere first. That's why I suggested LODing, though it may be worth checking out occlusion culling and other things as well.
     
  6. jamesjsewell

    jamesjsewell

    Joined:
    Jan 15, 2015
    Posts:
    5
    Thanks everyone for your replies, judging by your responses the idea isn't too far-fetched. I will definitely be utilizing an lod system.

    I'm sure I'll run into issues with batching on the instantinted objects, has anyone had experiences with that?

    Also, In the blender game engine you can use a ray cast that will return the hit polygon in a mesh which you can then manipulate the polygon and it's vertices. Is something similar possible in unity?

    I'm fairly new to unity and I'm making the transition from python and the blender game engine to unity. Right now I'm just kind of seeing what my possibilities are
     
  7. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    Of course you can, but this means making a copy of the mesh data and modifying it, which will mean more unique stuff (higher memory usage) and potentially make LODing harder.
     
  8. jamesjsewell

    jamesjsewell

    Joined:
    Jan 15, 2015
    Posts:
    5
    cool, that was just a curiosity of mine. I'm thinking of creating a tree chop system. When the player is near a tree it gets swapped with a tree that has a portion of the trunk where the geometry is fragmented, the outside layer of bark is uv mapped seamlessly over the fragmented mesh. When the players chops at it, the hit polygon is removed from the tree, then there are layers of wood chunks under this. The tree is felled when they've hit the trees choppabe section a number of times, then the tree fall animation sequenice is triggered. That's how the wood collection precess works. Obviously will be pretty difficult to manage and optimize but I think it can be done
     
  9. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    That could be quite manageable. You won't need to render many trees with that level of detail.
     
  10. jamesjsewell

    jamesjsewell

    Joined:
    Jan 15, 2015
    Posts:
    5
    True, any idea if altering vertices of a mesh will break the batching?

    I just remembered something that's been kind of holding me back a little in unity. I don't quite understand script execution. In blender you control when a script is ran and updated, you can control the frequency at which it is updated. In unity I don't really see that, all I know is that a script contains an update function which runs every frame. Isn't it bad practice to run your scripts every frame? Also is a function named update exclusively for updating?
     
  11. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    Yeah, it's bad to indiscriminately run things every frame, and Unity's most simple way to make things happen are indeed Start and Update methods. However, you can control when Update is actually called, and in a well-coded project most of your stuff won't be updating most of the time. I make extensive use of events and turns components on only when they need to do something. They complete and turn themselves off. Most of my components are doing nothing most of the time.

    For the limitations of dynamic batching I can only really refer you to the documentation, and suggest playing with it yourself on the target device to see how it goes and what effects it. It can be pretty fickle, and I don't want to give bad advice.
     
  12. jamesjsewell

    jamesjsewell

    Joined:
    Jan 15, 2015
    Posts:
    5
    ok I really appreciate your insight and I'll definitely begin going through the documentation and testing things out. It's nice to know beforehand that what I've asked about is in the realm of possibility, thank you