Baked Object Materials

   1882   5   1
User Avatar
Member
5 posts
Joined: Sept. 2013
Offline
I'm not sure if there's been a change in the latest Houdini Engine or if I've done something to break it, but previously when I baked an asset into a GameObject it made copies of both the mesh and the material (which I'm assigning via the unity_material attribute), but now it's only making copies of the mesh. This means all the meshes I'm generating from an HDA have the same material instead of seperate instances which is what I want. Anyone know what's causing this and how to fix it?
User Avatar
Member
571 posts
Joined: May 2017
Offline
If you are specifying an existing material via unity_material, then yes, it will just use the same instance for all baked objects, as well as the asset instances themselves. The reason is that by default for performance / memory reasons, this is the behavior you'd want in your project when using existing materials. (e.g. create a thousand copies of a tree, and instead of creating 1000 unique materials, all trees should share the same material your artist created for trees).

But I do see the need for having unique copies of a material in certain cases, so I'll add that to my list to implement. For now though, if you some experience with C#, you can set a Baked Events under the EVENTS section in the UI, and have a script to create a copy of the material on the baked outputs after a bake.
Edited by seelan - June 18, 2018 11:45:40
User Avatar
Member
5 posts
Joined: Sept. 2013
Offline
Thanks for the reply, that makes sense. I guess I must of been previously assigning the material in Unity and then baking out instances of the object. I think a good way around this would be to be able to select via checkbox when baking whether it's just the mesh or an instance of the material as well?
User Avatar
Member
5 posts
Joined: Sept. 2013
Offline
Just wanted to follow up on this as I'm fairly new to Unity and working out this HDA Houdini to Unity workflow as I go and you've got me second guessing my approach. What I have been doing is this:

In Unity I'm using Amplify Shader Editor to create materials with exposed parameters.
In Houdini I'm making HDA's which use the unity_material attribute to connect the material created above.
Once in Unity I use the HDA's controls to produce an asset I'm happy with which I then bake out.
I then tweak the parameters I've exposed on the material to make the new asset even more unique. (This is the behavior that no longer works for me as it changes the material on all the assets as the baking is no longer copying the material)

I'm attaching a video from earlier when I was getting the desired results (you can see each rock generated by the rock generator has the same shader/base material but a unique material is created when baked, and so the material can be altered on a per object basis.)

Again, I'm pretty new to Unity, so wondering if I'm going about this all wrong?
Edited by Frank Latter - June 20, 2018 12:22:33

Attachments:
rock_gen_2a.mp4 (14.1 MB)

User Avatar
Member
571 posts
Joined: May 2017
Offline
The plugin should have always used the same material even for baked outputs when using unity_material. The behavior that “worked” for you should not be the case by default, and could have been a bug.

For what you're trying to do, the easiest way to do it for now would be to bake your output, then create a copy of its material manually, and assign it to the baked output. Currently, each output is using the same shared material, so any change to one will reflect on the other baked outputs as well.

For a more optimized solution, if you are only changing shader properties but keeping the same material, the best way to do that would be to use something like MaterialPropertyBlock: https://docs.unity3d.com/ScriptReference/MaterialPropertyBlock.html [docs.unity3d.com]
This would be done via your own scripting class.
User Avatar
Member
5 posts
Joined: Sept. 2013
Offline
Thanks, appreciate you taking the time and clearing that up for me! Will look into the MaterialPropertyBlock. Have a great day!
  • Quick Links