#Baking discovered assets

1 messages · Page 1 of 1 (latest)

sweet axle
#

i want to bake an entire subfolder of assets into a dynamicbuffer of baked prefab entities

this "works":

class MySO : ScriptableObject { public GameObject prefab; }

struct R : IBufferElementData { public Entity prefab; }

class MyAuthoring : MonoBehaviour {
  class Baker : Baker<MyAuthoring> {
    public override void Bake(MyAuthoring a) {
      var buf = AddBuffer<R>(GetEntity(a));
      foreach(var r in Resources.LoadAll<MySO>("MySOs")) {
        buf.Add(new R{ prefab = GetEntity(r.prefab) });

...but it doesn't update when new assets are created; i wasn't able to find anything relevant to this in struct BakeDependencies

i can add a dummy variable to MyAuthoring that triggers rebaking but of course that requires manually incrementing it whenever something changes

is there a "blessed" way to achieve this?

if not i'm thinking of creating an editor tool that runs automatically on asset database updates, computes a hash of asset paths, and updates it into the authoring component in all subscenes containing that component, but that's a lot of work...

scenic plume
#

about to sleep so my answer is going to be short

#

but i basically just autoref scriptableobjects onto a 'manager' scriptable object

#
    [CreateAssetMenu(menuName = "BovineLabs/AI/Agent", fileName = "AIAgent")]
    [AutoRef("AIAgentSettings", "graphs")]
    public class AIAgentAsset : GraphAsset<AIAgentContext>, IUID
    {
        [SerializeField]
        private int id;

        public override int ID
        {
            get => this.id;
            set => this.id = value;
        }
    }```
#

AutoRef means any AIAgentAsset created will be automatically added to the AIAgentSettings.graphs field

#

this means my baker can just depend on AIAgentSettings

#

when a new graph as added to the graphs field, the baker automatically updates

sweet axle
#

hmm yea that makes a lot of sense and would be simpler

sweet axle
#

thanks, i'll try that approach!

scenic plume
#

the post processor that handles it

#

that's most of it, heading to bed though - thought i'd just give you some inspiration

#

there's a lot more extra in this solution for other features

sweet axle
#

yep that's just what i needed, i can probably whip up a minimal version for my current needs pretty quickly referencing yours

scenic plume
#

the iuid stuff is just a branch safe auto ID solution for assets, you can ignore that if you dont need

#

really just the autoref for your specific problem

#

just for completeness if anyone is reading and doesn't understand,

    internal class AIAgentSettings : ScriptableObject, ISettings
    {
        [SerializeField]
        private List<AIAgentAsset> graphs = new();
    ```
is the manager referenced in the AutoRef
tidal raft
#

Implementation is exactly same though

scenic plume
#

It's not really the same because you don't know if a random asset that appears needs to go somewhere, you just brute force it on all types

#

I'm actually familiar with your implemention now as I spent a couple hours today trying to figure out why it's broken.