Hey everyone,
I have been searching for this a lot online and I have also had my own attempts.
I want the player to build a house, instead of it just popping up, the player should see how it is being assembled one piece after another. Little example would be the upcoming game “Manor Lords”:
In this Trailer examples for that would be 0:15 and 0:23!
My idea was to create the house with all those Pieces as single Objects and then when creating the Prefab in Unity putting a script on it in which I would have to then have a List<> of GameObjects. Now I would have to give all the seperate Objects into the List in the order I want them to be put from “Disabled” to “Enabled”. With a simple Coroutine I can then enable them.
Even though this works fine I am having several doubts about this:
Already with very simple Objects I increase my Draw Calls like crazy.
Also this seems to be a lot of additional Manual work, giving the Meshes/Objects in Maya or Blender a naming convention, for example _P01, _P02, _P03… and then reading them out Unity would seem easier, but I am not sure how to approach this.
In general it seems pretty unclean to me, I am sure there are more issues with this approach.
Therefore my question: How do you guys approach this? If you use meshes which get combined, how would u handle stuff like Doors for a building which should maybe still be animated.
First, you can just animate the building process and then replace it with a static mesh when done.
Second… you can paint build order on object texture and use alpha cutout material for it. Basically, create a basic surface shader which cuts out invisible object parts based on specified threshold, on object being built slowly raise that threshold till everything is viisble, and then paint object texture in such way that objects that appear first have different alpha color on texture compared to objects that appear last.
If you want to animate each piece being attached to the structure, another thing to consider is that you can combine meshes at runtime. For instance, when all of the logs / bricks for a wall are in place you call a method on your script which copies the contents of all of their meshes into a new mesh, disables (or deletes) the old ones, and potentially even checks for and removes interior faces.
It could also be worth looking at DrawMeshInstanced(…), which allows you to draw many individual objects at a fraction of the cost of usual. The catch is that they need to all be matching, but if it’s building materials I doubt that’ll be much of an issue.
But, if you only need to see stuff once it has become a part of the house then @neginfinity 's solution, or some variation of that, is a much easier way to go.
So I believe you can remove a mesh from another. Problem would be that intersecting meshes would be removed in a boolean manner. Means you would cut it off at the intersecting part.
Yes, but it’d be trickier, as you’d need to know what meshes a thing was made of, and be able to re-construct it with the bits you’re separating not included.
For instance, if you’ve got a wall made up of 100 bricks, you’d need to know the position of each of the bricks before they were combined. Then when you take a brick away from the wall you re-create the wall mesh from the remaining 99 bricks, and create one separate brick object for the one you’re taking away.
But I’d only look at that level of complication if I absolutely needed arbitrary animations on all construction components and a simpler solution, such as using DrawMeshInstanced, didn’t get the job done well enough.