- Home /
Using Instance Nodes, worth it?
I am making a 2d game where there are various environments with lots and lots of objects. There is a forest scene with like 1200 objects in total(trees mainly), of which around 100 are visible on the camera at any given time, as you move through the level. These are comprised of around 20 different kind of trees and other props. Each object is usually 2-6 triangles with a transparent texture.
My developer asked me to replace each object in the scene with a node, and keeping only a minimal amount of actual objects which would be 300+ or so(?), since there are a few modified unique meshes. So he can instantiate the actual objects to keep the game light.
Is this actually effective? And if so how much?
I 've read about draw calls and such and I suppose that if I combine each texture (10 kinds of trees) in 1 mesh it will have the same effect?
Good point - missed the 2D bit :) Thought the meshes seem to have more than 2 triangles - which is what got me thinking that this needed to be a pseudo 3d solution.
Node/point is kind of like an empty game object. Which can be created in your 3d app of choice and imported as an fbx to unity. Basically in this case each node would represent a tree and the code would instantiate trees anywhere a node is present.
Answer by whydoidoit · Sep 29, 2012 at 09:15 AM
Well you don't really want to be instantiating those objects during game play if you don't have to - that is a pretty expensive operation. What I would do is put all of the objects in the scene and then turn off the renderers for the ones that shouldn't be in view.
I can't think why the size of the game would be improved that way either - the only thing that might improve by all of that instantiating is the load time of the scene. That could be improved by disabling all of the initially hidden game objects too.
I guess another argument might be that you are taking up memory for objects that never come into view. That would make more sense perhaps - again disabling them would remove much of this overhead. I'm presu$$anonymous$$g that trees don;t have many scripts attached to them that are allocating lots of memory in any case.
Thanks for your answer. Sorry if I wasn't clear, there are 100 visible objects on camera, but not the same ones all the time. You can think of it as a filmstrip and each strip has 100 objects in it. So all 1200 gets shown but not at once. Is there a way that you can load progressively as the player walks down the level? The trees as you said don't have any scripts on them.
Yeah I got that. I can't see what you are really saving by instantiating them as you go apart from potentially level startup time.
If you want to save draw calls - turn off the renderer (by adding a script) when the object should not be visible.
If you want to improve startup time you could:
a) Split the level into parts and load them additively with LoadLevelAdditiveAsync b) Do what you are doing - but it has an in play cost.