How do I link assets with each other via script in editor?
Hi, I am trying to assign a sprite to a newly created tile via editor script.
//
//
I've tried a few ways.
//
//
Attempt 1
// create tile
AssetDatabase.CreateAsset(ScriptableObject.CreateInstance<Tile>(),
tilePath);
// assign sprite
Tile tile = AssetDatabase.LoadAssetAtPath<Tile>(tilePath);
tile.sprite = AssetDatabase.LoadAssetAtPath<Sprite>(spritePath);
//
//
Attempt 2
// create tile
AssetDatabase.CreateAsset(ScriptableObject.CreateInstance<Tile>(),
tilePath);
// assign sprite
AssetDatabase.LoadAssetAtPath<Tile>(tilePath).sprite = AssetDatabase.LoadAssetAtPath<Sprite>(spritePath);
//
//
Both attempts manage to assign a sprite to the created tile BUT the relationship would get removed after a while.
//
//
I'm assuming this is due to GC removing the sprite from memory. Meaning that the assignment was not referenced directly from the asset, but one referenced from memory.
//
//
apologies for the crappy formatting, I have no clue how to add empty lines
Your answer

Follow this Question
Related Questions
How to change Texture in editor 0 Answers
Any way to set AnimatorOverrideController's animation clips programatically? 1 Answer
How to get mouse click world position in the scene view in editor script? 3 Answers
Error loading auto-generated monobehavior at run-time 0 Answers
Load an array in editor while keeping unity running 0 Answers