Is there a way to import a mesh, with it’s associated colliders and scripts from one scene into another? I understand that “packages” can be used to move assets from scene to another, but that doesn’t include any empties or colliders in the scene.
I guess what I’d like to be able to do is “merge” two scenes. Any way to do this?
Not that I know of. You could make prefabs out of the stuff you want to combine and export those as packages, which might be a bit of a pain, but unless someone knows better…
That’s what I was afraid of. I’ve got a pretty complex mesh that is part of my environment and I used box colliders parented to empties to build the complex collision matrix. It’s got lots of nooks and crannies and this seemed the best way to do it.
I also have a pretty complex vehicle that is done in a similar way. The vehicle has moving parts that need to interact with the environment’s collision matrix.
All pretty complex stuff. I’m not even 100% sure Unity can handle it, but I’m gonna give it a try anyways…
At any rate, I had hoped to build it in pieces and then assemble the pieces at the end. Unfortunately, I haven’t figured a way of doing this in Unity. The meshes and textures move from one scene to another OK. But none of the other stuff does (scripts, empties, colliders, etc.).
Do you mean between scenes, or between projects? I’ve had luck just selecting the object I want to move over in the hierarchy and then copy/pasting into a different scene. I don’t know about moving them between projects, though.
Any particular reason for not using a mesh collider?
Anyway, that and the vehicle sound like prime candidates for a couple of prefabs. Build want you want, then make a prefab out of it (prefabs can be anything), then export the prefab. You shouldn’t have any issues. It’s only a problem if you have a big scene with lots of different items. A few complex items are no big deal.
Also, Marble is right…I was thinking about different projects, but scenes in the same project is another matter. Still would probably be worth making a prefab out of the vehicle just so you have more flexibility with what you can do with it.
First, I was under the impression that box colliders were faster / more efficient than a mesh collider. I’m pretty concerned that my scene is going to be too complex for Unity to handle, so I thought it might be better to use a bunch of box colliders than a mesh.
Second, my “environment” is basically a terrain mesh with a tower made of posts and girders. I made a box collider for each of the posts and girders. I don’t want to combine the tower and the terrain because I’m using different textures / materials for each. I’m afraid that using mesh colliders for both would cause a big framerate hit, so I’m using box colliders.
I’d gladly use mesh colliders instead, as they are -so- much easier to set up, but not if it means a big framerate hit.
I’ll have to study the docs a bit more. Haven’t touched prefabs yet, so I need to study up on them.
Everything is in separate projects at present. I was running into problems with my file management so I started breaking things up into smaller pieces.
I still haven’t figured out a good way to manage files in Unity. I think it’s because I’m using Blender and my workflow involves alot of “back and forth”. I tend to design something, then go back and tweak it until I like it. This is fine in Unity until you have to “break a prefab”. This is the case with my vehicle. It has multi-jointed, robotic arms and in order to get the hierarchy right I have to break the prefab in Unity. I end up doing a lot of things over and over, because when I re-import my changed mesh into Unity, I have to go back and fix the hierarchy and scripts.
I did that for a while, too, but found it more convenient in the end to write a script that attaches all my components and things at runtime. That way, the prefab remains. This was easy for me because I had a lot of things named “Door” and “Table,” etc.
It would be nice to have an easy way to move many interreliant parts of a project into another one, though. Sometimes I am reticent to send bug reports because my project folder is enormous and it’s too difficult to extricate the problematic objects into a package.
In my case, I think I’ll be pushing the physics engine to it’s limits, so I’m trying to find ways to reduce it’s “load”. Hard to describe, but I won’t be able to show anything for another week or so.
Yup. Same situation. That combined with a bug in Blender that made the files grow exponentially made bug reporting kind of difficult. I now create 2 sets of Blender files: One set is my “working” set that I tweak in Blender. Then I strip all the unnecessary bits out of it and copy it to my assets folder.
A box collider is faster than a mesh collider; however, a lot of box colliders is unlikely to be any faster than a complex mesh collider and might even be slower. One of my projects has a number of high-complexity mesh colliders and I haven’t seen any particular slowdown in that area. (The slowdown comes mostly from using pixel shaders for everything; it starts getting down to 100fps in some spots with high res/high FSAA, but hits 330fps or more if I use minimum settings.)
Save yourself the massive headache and just use mesh colliders. Generally there really isn’t any speed issue. The only downside is that there’s a pretty big performance hit when calculating the mesh collider for the first time, or recalculating it after modifying it from scripting. PhysX does heavy processing on it the first time, so it’s fast in normal use. It takes a lot to push the physics engine to the point where speed becomes a problem. I mean a LOT.
That’s odd…when I change meshes in Blender, they’re auto-updated and I never reimport anything. I can change meshes on the fly even if the game is running (although I have noticed that mesh colliders aren’t updated when I do that). In the worst case, you should at least be able to drag new meshes onto existing objects (see attached pic below).
Don’t forget that if you change prefabs and “break” them so they’re not prefabs anymore, you can simply click on the ex-prefab after you’re done changing it, and do the menu item GameObject → Upload Changes to Prefab. Then it’s a prefab again, but with all the changes applied. Or maybe I’m misunderstanding the situation.
Thanks Eric. I’ll give mesh colliders a try and see what happens. It’s certainly tons easier to do than all the boxes I spent hours setting up this afternoon.
Incidently, I’m lucky to get 45 fps on the “simplified” version of this sim, much less 100 fps (on my iMac Intel Duo). Besides the complex terrain and tower, a vehicle with robotic arms and claws that the user can use to pick up things, the vehicle is also connected to a tether that floats around in space. Lots of physics stuff going on.
Hmmm… I’ll have to give that a try. Not sure if it will work, but shouldn’t be hard to find out. Thanks!
It’s far more likely that rendering the objects is the cause of the slowdown. Also, check out the section in the docs on optimizing speed if you haven’t already. From what you’ve described about what you’re working on, 45 fps sounds excessively slow, though of course I haven’t seen anything first-hand.
Just out of curiosity, since the project I’m working on right now (if I weren’t posting this ) has a 4000 poly terrain mesh with a collider, I did a test at minimum resolution and quality settings with the terrain rendering turned off (but the collider still active) and no other objects visible other than the sky, so it would be almost entirely a CPU-bound test. I got 880 fps. I then duplicated the terrain mesh a dozen times, so I had 13 meshes each with a mesh collider, for a total of 52,000 polys that you can collide with. This got 590 fps. Then, I put in a lot of big alpha-blended objects and totally maxed out the resolution and quality settings. With one terrain object I got 53 fps, and with 13, I got 52 fps.
Therefore, we can conclude that my opening sentence was correct, and that rendering stuff on screen is WAY more expensive than calculating it with the physics engine.
I’m using Cinema 4D, and if I break a prefab (a long object hierarchy) by adding components, even if I make it a prefab again, the gameobjects that I had added components to turn into snarled messes of geometry when I resave the hierarchy in C4D. This is one of those instances where it was easier to work-around than send a bug report .
If all you want is copy some objects from one scene to the other, you can use copy paste for that. Simply select the object you want to copy hit cmd-c for copy, open the other scene and hit cmd-v for paste.
I did some experiments and have some disappointing feedback:
My scene has a 1000 poly vehicle, 1600 poly tower and 960 poly terrain. When I played the scene without using mesh colliders, I was getting about 90 fps (iMac Intel Duo). After adding a mesh collider to the tower and terrain, my framerate dropped to 45 fps.
I also toggled the textures from single color “diffuse” to textured diffuse, to bumped diffuse with negligable changes in frame rates.
Hmmm… Didn’t work for trying to copy a mesh with it’s associated material and script. Also wasn’t able to copy/paste multiple objects at once.
The only way I’ve found to carry everything from one project to another is to make a duplicate directory and rename it. Then open the duplicate project and delete whatever isn’t needed. Kinda ugly way to do it, but it’s faster than re-doing everything by hand.
Did you test that in the editor, or with a stand-alone (and make sure vsync is off)? Although even in the editor, I wouldn’t have expected any noticeable drop.
Tested in both editor and stand-alone. Might be related to another thread I started regarding rendering problems with fog. I think I’ve fixed that problem (at least found a work-around) and suddenly my framerates jumped up to 60-90 fps.
Make sure the “Sync to VBL” box is not checked for whatever quality level you’re using (though it’s always on in the editor). That can only slow down your fps, though it can also reduce screen tearing. When I see stuff like fps going from 90 to 45, that usually tells me vsync is on…if you’re just barely getting 90fps, for example, and you have vsync on and something happens to reduce the framerate a bit, then suddenly it gets halved instead of just going down to 89 or whatever. You should only use vsync if you’re sure you can maintain a fps that exceeds the refresh rate of your monitor. (Which with LCDs is usually around 60, even if “refresh rate” isn’t quite accurate in that case.) But definitely never use it for benchmarking, since you can’t get accurate results with it on.
If you want to copy some game objects with dependencies from one project to another you do like this:
save the scene where you have the object you want to copy over
In the project view, select the scene and all assets you use in the scene
Export package
Open the other project
Double click the package to import it
Now copy paste which ever game objects you want to get out of the scene.
The frame rate in the editor is always clamped, because you don’t want to max out frame rate when working in the editor. So if you want to do performance comparisons use the standalone player.