- Home /
How can i use the Instancing in max to Place/Replace/Instantiate in Unity
I have an array of items in a 3dsmax FBX file, i name the objects as 'instance_objName##' and would like to use an AssetPostProcessor to utilize instancing in Unity
My initial attempts to even get the AssetPostProcessor to do anything are failing so far, this seems a good of a spot as any to record the progress :)
using UnityEngine; using UnityEditor; using System.Collections;
public class AssetPost_InstancesByPrefix : AssetPostprocessor { void OnPostProcessModel(GameObject g) { Debug.Log("Never gets called? " + g.name); ProcessInstances(g.transform); }
void ProcessInstances(Transform obj)
{
Debug.Log("WTF doesn't this work " + obj.name);
foreach (Transform child in obj)
ProcessInstances(child);
}
}
Answer by BogdanDude · Jan 09, 2010 at 10:47 AM
Check out this editor script I wrote: http://forum.unity3d.com/viewtopic.php?p=237536#237536
It will make your instancing automatically, going from your 3D app to Unity (automatically places the prefabs).
Thank you, I was actually just adding a generic-Instance-Replace type script to my list of things to build~
Answer by Lucas Meijer 1 · Dec 11, 2009 at 07:32 PM
It's not getting called because you forgot to make it static. I should really just add some sort of check for a nonstatic version and throw a warning, as this seems to trip up many people. hmm, I think I even added a "If it doesn't work you forgot to make it static" note to the help page :). On a different node, why do you think you need to do this in the first place?
Honestly i'm not sure, I'm experimenting and looking for ways to streamline the general process for Architectual work, and was thinking that maybe if my 30some fairly high poly objects that are identical were all using the same meshfilter there would be some sort of performance benefit over have individual unique copies of the same mesh
I think this is absolutely essential. Unity does not have appropriate tools for content creation. Therefore, the only realistic solution is to do all non-terrain level editing externally. The mesh situation does save on memory, but more importantly, it's a lot more than meshes that can get stored in prefabs. I don't use the AssetPostprocessor, though. I tried it, ran into several bugs, and later realized that I didn't want the process to be so automatic anyway. Now I just run a script that instantiates prefabs if anything in the fbx contains a certain name.
Answer by davebuchhofer · Dec 12, 2009 at 07:18 AM
The trick i was looking for was actually the Combine Children script! that drastically improved the problem of tons of 3dsmax instances.