x


Can I generate prefab instances based on locators inside a 3d model file?

I have quite a complicated spatial setup going on in one of the scenes i'm working on. At the moment I've placed them by hand, but as the number of elements increases and art changes continue occurring its growing frustrating having to do this manually.

I wonder if there is any accepted way of harvesting out certain elements from an imported 3d model and using their position and rotations to create the instances of a given prefab. I guess i'm talking about an editor script which could take the pattern of the names of locators to search the model for, and the prefab to create.

I don't know if actual modelling locators themselves are even imported as they usually don't contain any geometry. At the same time I guess I don't want to waste any time rendering anything that is only present to be a locator for this purpose.

Finally it'd be great if this is at all possible that subsequent imports could have the script update already created instances rather than creating new ones, otherwise the values set for script members on the instances would be lost and i'd have to start again with their setup.

more ▼

asked Jan 05 '10 at 08:26 PM

jimbobuk gravatar image

jimbobuk
1.1k 34 42 54

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

I'm not sure if this matches what you need, but I use Blender as a level editor instead of Unity; what I do would work with any 3D app, however. This has gotten kind of complex, and I'm still working on it. (I don't even know what all I've added since I made the forum posts.) I will be putting a cleaned-up version on the Wiki, with complete documentation, once my next game is out, but feel free to check it out.

Working with Unity, and syncing assets, is kind of a freaking pain if you're not using prefabs, if you need your objects to have scripts applied. (Currently, trying to make a copy of a script and attach it to something else seems to be completely undoable, due to bugs, according to me and a few others who have tried.) But if you are using a lot of prefabs, and/or scriptless objects, I believe this solution will work out well for you.

You mention needing to have unique instance variables. Marking something as a "Clone" in this script can accomplish that. However, that takes away from the power of syncing in ways that I haven't even had time to come up with yet. It might be what you're looking for. Maybe run the complete sync once, then "Clone" all the instances, and set up their scripts as desired. Future syncs will keep these values, but update the transforms as dictated by your 3D app. Also, if you make any mesh edits, that will come through as well.

Personally, I have been just syncing my entire level, then running a Menu Item setup script afterwards that sets up all my unique instance variables. Whether that is appropriate for your use, I don't know.

I'm uploading my latest version right now. http://forum.unity3d.com/viewtopic.php?t=32551

more ▼

answered Jan 06 '10 at 12:32 AM

Jessy gravatar image

Jessy
15.6k 72 95 196

thanks, i'll take a look when i'm next at the keys. Now i'm back at work its harder to find the time (and energy) for home dev!

Glad that i'm not the only one to come across these sort of dilemmas!

Jan 07 '10 at 11:08 PM jimbobuk
(comments are locked)
10|3000 characters needed characters left

This should be possible with an editor script, but I'm not familiar enough with how exactly Unity imports external models to give you a script. However, you should be able to somehow get a list of locators by giving them a specific name, and searching for objects with that name, or something similar.Then just iterate through the list with a for loop, Instantiate() a new object, and copy the position, rotation and scale of the locator.

more ▼

answered Jan 05 '10 at 11:40 PM

Stelimar gravatar image

Stelimar
3k 14 16 50

I guess the question is whether locators even make it into unity to be searchable. I was thinking about this some more and wondered whether empty groups could work which i then place the instantiated prefabs into correctly. Then if the groups are moved in the model the prefabs SHOULD be. Thanks though.

Jan 06 '10 at 12:25 AM jimbobuk

I'm not sure, but you can always try it and see if it works.

Jan 06 '10 at 01:33 AM Stelimar
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1259
x973
x574
x348

asked: Jan 05 '10 at 08:26 PM

Seen: 1734 times

Last Updated: Jan 05 '10 at 09:12 PM