Asking how to change an asset and save it

Hello,

As the Editor scripting docs are clearly lacking of indepth infos, I’m begging anyone’s charity to show me a simple thing :

I just want to manipulate an FBX asset and save the result in a new asset.

Clearly, I want to create new animation clips into it, from the existing ones.

I’ve been on trial and error for some days now, but still can’t manage to save the changed asset properly. It loses changes on Unity restart. And basically I’m finding that simple asset handling is not intuitive at all.

Could someone post a step by step script, which would simply take an fbx asset, make it editable (manipulations are on my side, don’t worry with that), and then save it to a new .asset file.

Thank you for your attention :slight_smile:

You can make new assets in Unity’s internal format based on existing assets, but you can’t make changes to an FBX file and re-export it as an FBX that can be read by other software. (Maybe you could do it with a heroic scripting effort, but there’s no API for it.)

Yep, I didn’t express myself very well :wink:

In fact I just want to manipulate an FBX and save the changes, whatever the method is.

Actually I’ve found a working (but painful) method, by duplicating the FBX element by element, making changes, and then save the result in a new asset.

But as Unity Editor docs don’t have any info on how assets internal hierarchy is handled, I’m having a very hard time at building this new asset.

For example, I have managed to recreate the Animation hierarchy (thanks to trials and error), but I’m stuck at the present time with repopulating the new asset with child gameObjects of the FBX.

In short, it would be really, really helpful if a Unity guy would post a short tutorial about how to create an asset from scratch. Here, an FBX-like asset would be perfect, and would come handy for all the devs who want to rework their models animations under Unity.

Bump.

Please Unity support, would you mind posting a short tutorial about how to create an asset similar to an FBX file, and that wouldn’t crash ?

Like how to place hierarchy, nested gameObjects and stuff.

(actually I even ran into a created asset that would make Unity systematically crash at launch).

if the hierarchy is in the model you don’t need to do anything as the bone hierarchy is reflected as transform hierarchy in unity.
So if you are able to create all in the modeller directly through the skeleton hierarchy it will likely be the fastest way.

if there is no such thing or you want to create a new hierarchy, then you need to keep in mind that you will have to update the assets manually because nested prefabs are not possible, as such your model will not automatically update if you modify it externally.

As for the hierarchy itself: you would create them in the scene hierarchy until you are fine with them, go to the project panel and create a new prefab and then drop your scene hierarchy into it. That way you have a new “replicable” scene object with self created hierarchy.

I hope that one+ of these different answers answered exactly that part you were actually asking for.

Thanks Dreamora,

actually this is a bit more complicated than just copy pasting an already existing FBX :slight_smile:

Why I want to be able to recreate an FBX hierarchy in a new asset is because I want to manipulate an imported FBX. As editing imported FBX is forbidden, we’re forced to recreate an identical asset, and then do what we want to it.

So I would be in the second scenario you described : create a new hierarchy (from an existing uneditable one).
I’m precisely updating assets manually, but it keeps crashing or showing me leaked components, unless I manage to find the function to use, in the right order, to the right hierarchy level.

For example, If I create a new rootGameObject, put every cloned components and child gameObjects into it, and then use CreateAsset(rootGameObject, “anyPath”) , it doesn’t work. Unity tells me that its child components are leaked and then delete them. On restart, nothing is saved and the file only points to an empty GameObject.

For it to work, I have to first CreateAsset(new GameObject), and then AddObjectToAsset() some components into it, like AnimationClips and Mesh. If I add all the components, it will crash on reload.

At my actual point of achievement, I can only succeed at correctly reproducing the root gameobject, its self components, and its animationClips.
No leaked components anymore.
But I’m stuck with nesting to this new asset all the original FBX child GameObjects : I can add child gameObjects to the root asset, but according to native Unity FBX hierarchy, we can’t add every childs into the root asset. We have to add only its first childs, and then nest their own child into them.

→ Anytime I try to perform AddObjectToAsset() on these child GOs, they just ignore any parenting I assigned, and show to be nested to the root asset.

It’s such a pain :frowning:
But thank you for your interest, that’s kind.

Regarding storing assets, Bas made a great tutorial in his blog:

http://bassmit.info/?p=68

Maybe it helps.

Thank you Martin, I’m going to work it now.

Well, I tried to find a simple way to use Bas’s script, but it seems like we have to recreate every single variable of the classes we are copying.

I’m continuing to work on it, but still, it would be really useful if some Unity guy came and showed us how are we supposed to create new FBX-like assets.

I’m losing too much time, I gave up.
I’ll just content myself of an .ANIM asset for now.

Submitted the request via a bug report, hoping to have an answer.

I’ll make sure to share it to the community.

Thanks guys for your support.