Am editing a level in our 3D tool of choice and using placeholder dummies for various things.
Adding components to the dummies works fine in AssetPostProcessor, but instead of delineating every tweaked variable on a component in the AssetPostProcessor script, would prefer to just swap out the dummy object for an existing prefab and make any changes to the prefab.
Can the AssetPostProcessor pipeline be used to swap out gameObjects with prefabs?
Have made an attempt using OnPostprocessModel(), but either the “swap with prefab” code gets ignored, or the attempt goes splat!
Guess I should have been more clear eh? Am using OnPostprocessModel() of course Editor.InstantiatePrefab (!) but am getting null refs on the prefab var when I think I shouldn’t.
Here is the relevant test code…
var assetPrefab : Transform;
if (transform.name.ToLower().Contains("half")) {
assetPrefab = EditorUtility.FindAsset("Prefabs/Level/Disc_half.prefab", Transform);
}
if (!assetPrefab)
Debug.Log (Time.time.ToString("f2") + ": "
+ "Error processing imported file: " + "Prefab is null!"
);
}
And every import, the log is being hit for each occurrence of “half” in a model name. Have verified the path as valid, have included the extension, but it yet fails. No idea why.
Got it to instantiate the prefab using the original code (changed only the code layout, due to the previous spitting errors when not desired) but still am not able to replace the dummy object exactly.
The last line causes Unity to crash horribly horribly.
So it seems there isn’t a way to swap a dummy with a prefab cleanly, unless I want to ignore my nice, clean and helpful hierarchy (which is like trading useful features for each other; why do I have to pick choose?)
Inherently using AssetPreProcessor has strengths, but when trying to replace an imported dummy with a prefab (keeping it in the same hierarchy as in the fbx), find I am fighting Unity to do this…
If it takes this much hoop-jumping to replace a dummy with a prefab, thinking a ReplaceWithPrefab() method would do nicely! Otherwise, seems AssetPreProcessor doesn’t play nicely with prefabs
on a quick look, this seems to make an infinite recursion, because the object that you add actually has the word “half” in it, and after you add that, you recurse over all children again.
Not saying there is no bug here, just the first thing that comes to mind when looking at this code, please post your casenumber in this thread for reference.
If I understood you, you’re saying that instantiating a prefab as transform causes Apply to run “over all children” again?
Otherwise, not sure where the “over all children again” part comes into it. Though I’m recursing over each child, but don’t see how adding a prefab causes that to repeat for all children.