- Home /
Passing variables to LoadLevelAdditiveAsync
Im currently looking at using LoadLevelAdditiveAsync to improve loading the large tiled city i dynamically generate by streaming the tiles as the player moves around.
My idea is to have a single scene with a gameobject/script that instantiates the required prefab and sets the tiles rotation(the same tile can have 4 positions) and position plus, any additional street decoration.
I would then call that scene with LoadLevelAdditiveAsync but the problem is how do I pass the prefab/rotation/postion info.
Any ideas?
You can load in a whole scene, not parts from inside it.
Otherwise you'd load resources.
Sorry but im not sure what you mean.
Currently on a mid size map im loading 500 prefabs with each prefab containing 2-6 building models. each prefab currently 50 unity units square.
The issue centers round the problem of instantiating 2000+ objects and thats without starting to add any serious detail
For the additive loading approach you need to make smaller scenes with these prefabs contained and set up. LLAA call will load in a scene, not prefabs. To load in prefabs you use the Resources Folder.
Oh I see what you mean now.
$$anonymous$$y reason for using loadleveadditiveasync ins$$anonymous$$d of resource load, is im trying to mitigate the freezing up of Unity as it tries to instantiate masses of complex prefabs in one hit.
And so my intention is to create a type of dynamic strea$$anonymous$$g but ins$$anonymous$$d of using on a sliced terrain i want to use it on a sliced city, which happens to be made up of dynamic prefabs.
If i did it the traditional way of a scene slice i would end up with 1000's of scenes.
Unless ive missed the point of load resource.
Any constructive advice is appreciated.
Answer by jnt · Mar 12, 2015 at 03:01 PM
We are creating a similar environment.
This subject has been discussed before somewhere else that I can't find right now, but, one way to do it (but I'm not sure how this is going to affect the performance), is to have your whole scene in a parent object, then in a script get a reference to that object using:
GameObject.Find("parentObjectName");
Then manipulate it's transform rotation/position to how you want it.
The problem you are going to encounter is moving the navmesh and loading the lightmaps.
Unity are working on resolving the lightmap issue, but as for the navmesh, we've decided to use the A* Pathfinding Project for creating navmeshes that we will be able to move, and that is working for us so far.
makes sense but how do you get around specifying which prefab you want.
I have a grid made up of prefabs with each gird space/prefab chosen randomly/dynamically.
So do you have a scene for each prefab and then limit the amount of prefabs you can pick from?
Yes you would just have each "tile" as a scene, with the root gameobject containing all art objects - whether they are prefabs or not is inconsequential. You could still pick the scene you want to load randomly, then position the root gameobject at the right place in the world.
So do you have a scene for each prefab and then limit the amount of prefabs you can pick from?
I don't think this would limit you any more than loading prefabs, I'm sure you can additive load a scene more than once... but haven't tried.
Answer by Hybrid1969 · Mar 16, 2015 at 01:38 PM
Update:
Although I did find some interesting solutions, I was unable to get this to work in the way i wanted.
However in trying out different solutions i discovered that a runaway Co-routine had been happily running in the background slowly but surely causing chaos to my map generation and rendering, sucking up valuable frames for no reason.
WARNING TO ALL or (How to waste a lot of Dev time needlessly)
Co-routines are great but an absolute menace if your not careful. Keep track of them, especially if you are nesting them and don't use them if you don't have to. I am working on a sensible way to keep track of all my co-routines so Im not a berk again.