- Home /
Question by
Briz · Aug 02, 2012 at 03:25 PM ·
assetfbxassetpostprocessor
Grab one child of an imported FBX asset
When importing an asset of file type .FBX, I want to add components automatically, like a Rigidbody. However, with my current code, it adds a Rigidbody component to each child of the imported asset. I want that only one of the children (which will have a specific name) to have the Rigidbody, and not the shadow or plane.
I'm not sure how to grab only one of the children of the imported FBX asset rather than all of them (courtesy of GetComponentsInChildren
). Example code is given below, which adds a Rigidbody to all children of the imported asset.
using UnityEngine; using System.Collections; using UnityEditor;
public class AssetPrefabCreator : AssetPostprocessor {
public void OnPostprocessModel(GameObject g)
{
if (assetPath.Contains("model"))
{
Renderer[] allRenderers = g.GetComponentsInChildren();
foreach(Renderer R in allRenderers)
{
// Adds a rigidbody
R.gameObject.AddComponent(Rigidbody);
}
}
}
}
Comment