#Need suggestions for implementing asset custom dependency

1 messages · Page 1 of 1 (latest)

raven gale
#

Hello, in a previous post, #1395170695633436732 , I was having trouble with a warning message saying " Warning, Importer gave inconsistant result when importing specific asset.

For some background, i have an asset importer, that asks a singleton instance if it should change anything about the file its trying to import. i have editor tools and methods that perform operations on the singleton, changing its answer for specific imported models that the user chooses. when reimporting the file right after changing the values, it gives the error message above.

if i decide to add the singleton as a custom dependance for any model i import, if i add / remove / change a single asset it would reimport every asset with the custom dependacy. i could change it so each model uses a specific scriptable object .asset, but that could create alot of garbage / saving / loading singletons for each model if you have like 1k models.

anyone have advice on ways you could solve this problem? Am i entirely wrong in my thinking of how you would be able to select specific objects to change? any advice is appriciated.

primal palm
#

what was wrong with the original solution? I haven't tried it myself but registering a custom dependency using the path name and a hash of whatever settings your singleton has should work

primal palm
#

okay I tried it and it works fine. Better to use some combination of a prefix + guid instead of a path name though so you don't have to worry about assets getting moved

primal palm
raven gale
#

and yeah, i store guids rather then path names. guids stay no matter where in a project the asset is

#

like for example you add the singleton to 300 assets as a dependancy, and then you change it so that it changes the value of one of those 300 assets on the singleton, it reimports all 300

#

ok wierd, i thought registering custom dependancies meant you had to register asset files as dependancies, if you can also register in-memory objects as dependacies that changes things

#

thank you for sharing the test code

primal palm
#

sure, hopefully it helps

raven gale
#

helped a bit, I now can change the default import customization, but if i change a value of the class/struct it doesnt actually reimport. im guessing thats because i need to manually update the hash using RegisterCustomDependancy.

#

Nope, im doing something wrong with registering Depedancies. figuring out what specifically im doing wrong and will message again. When i change the value of a part of the class / struct that has the custom dependancy, it doesnt reimport the asset, or looks like they arent connected at all

#

heres the relavent code, seems like i just, cannot understand how unity handles connecting dependancy names, to registering custom dependancies

#

no matter how i handle registering or connecting, i cannot connect the class to the postprocessor.

#

Maybe its completely due to how the data class is being edited / stored a ref to inside a dictionary, a non-serializable class, but other then testing, im scratching my head at the top leve reasons this doesnt work

raven gale
#

Ok, figured out that if i give it the guid as part of the hash, it seems to actually, you know, allow the assetDatabase to distuinguish between different FBXDdata

primal palm
#

yes, you need to change the hash in order to trigger reimport

raven gale
#

i did change the hash using some editor functions, and when i change it, now, it doesnt trigger a reimport, but still allows me to reimport without a warning that the importer is inconsistant

#

wierd that i actually needed to provide a guid for the hash, im guessing you cannot store different assets as custom dependancies with the same hash

#

if you see that line i commented out in the code that checks if the hash changed, i do change the hash in whatever method calls it, but it doesnt actually reimport the asset, which means something is wrong with my dependancies still

primal palm
#

what does FBXData.Instance resolve to? I had weird results too where it looked like things weren't being imported correctly, and it turned out that parallel import was creating multiple singleton instances with outdated data

raven gale
#

Thank you so much for all the help btw, this is very confusing because its not well documented, same as like VisualElement.SetBinding();

primal palm
#

log the instance id of this both when you change it and when your asset importer runs, that was my first clue

raven gale
#

its a class with a static instance that references an .asset file

#

instance id of the FBXData or FBXDatabase Instance, or the Postprocessor?

primal palm
#

the way you have set this up is weird. Why are you loading an instance from disk, and then ignoring it immediately and potentially overwriting it with a second instance you create?

raven gale
#

I check if there is an .asset file at the loaded asset path

#

if there is, i exit the method

#

otherwise i create an asset at the provided path and connect it to a new instance

primal palm
#

oh I see, you load if and if it fails, you load it again which will definitely fail and then create a new instance

raven gale
#

idk why i decided to load it again tbh, didnt look back at it

#

ohhhh

#

i remember, i never actually finished it

#

if you try to load assets during a InitializeonLoadMethod, the assets can be not imported yet, so doing an importAsset can ensure the assetdatabase loads the asset

#

a second null check should be right before the debug.logwarning, fixing it

#

and im completely dumb, i forgot to do an AssetDatabase.Refresh after executing a hashchange, everything works now, but if you have any extra advice on code ill take it

#

though i still do not understand why you need every single custom dependancy to provide a unique hash id

primal palm
#

that's how you link your particular model to a set of changes in the list

#

ideally you'd have these extra fields in the asset importer itself, but when I tried to make that work it was ... ugly

raven gale
#

i meant that if i have 5 FBXData, they each need a unique hash, they cannot share the same hash, even if they all contain the same data (besides the fact that they are connected to different asset guids

raven gale
primal palm
#

replacing ModelImporter with your own editor so that you can add your settings directly on the model

raven gale
#

I wanted my data to be saved completely seperate from the models themselves, so i thought of using a single SO .asset

primal palm
raven gale
#

like the dependancy name contains the guid + padding, but i needed to add the guid to the hash wierdly

#

I do have an FBX Parser i made that i can write the model data to the fbx's file itself if needed, but i thought of having a single datascript would allow you to swap my plugin between your projects if needed, or connect to a specific package,

primal palm
#

did you test this after you fixed the refresh issue?

raven gale
#

i meant like if i take the guid out of the modeldata. hash, it doesnt connect any model to any depedancyname

#

not in the code i sent, sending a new version

primal palm
#

so your previous code only works if you use GetHash with the guid?

raven gale
#
//doesnt work 
AssetDatabase.RegisterCustomDependancy(FBXData.GetDependancyName(guid), model.Hash)

//Works
AssetDatabase.RegisterCustomDependancy(FBXData.GetDependancyName(guid), model.GetHash(guid))
#

yep, exactly

primal palm
#

I don't know why that would be, including an unchanging guid in the hash result doesn't do anything special

raven gale
#

i think unity under the hood uses the hash in some way to differientiate dependacies

#

i retried it with model.hash, and yep bug comes back

#

only thing that it does is remove the hash collisions between all the different model data

primal palm
#

there shouldn't be any colliding since they're all separate and combined together with other dependencies for a final hash

raven gale
#

because most FBXData will give same hash results

#

what happens if FBXData is the only dependancy for a model?

primal palm
#

then it will be the only extra dependency added to the hash of the asset + its settings

raven gale
#

alright, wierd then. since its not runtime issue, and it doesnt increase the memory footprint, im just going to leave it at some quirk with customDependancies and hashes. Dont have the time to worry about it right now but may be a interesting thing some other time. thank you for all your help, it fully works now, just need to do some prettifying to this asset and its ready for the store

primal palm
#

my go-to when I see weird things happening is to rebuild the library, but I don't have any other suggestion beyond that. It shouldn't matter, but if it does I'd add a comment explaining why it's there for future you and continue on :)

raven gale
#

still having the inconsistant import problem when trying to connect ctrl + z to this workflow, but ill figure it out after i take a break to eat lol

#

(probably user error on my part)

primal palm
#

works for me. Are you calling AssetDatabase.Refresh on undos too?

raven gale
#

Think its to do with registering a custom depedancy, then removing the custom dependancy from the list on an undo (via SO diff)

#

but will figure it out myself, (i do an asset refresh on undo) (Think i just need to repurpose an undo class i was gonna use to just register things with the dictonary with default values on undo)

raven gale
#

sidenote, registering a custom dependancy causes a full AssetDatabase Refresh