Consider the following script which takes an existing texture object, creates a copy of the texture file, copies that file to Resources directory, then immediately loads the new copy as the texture object:
string m_resourceFolder = "RoomTextures1";
Texture2D texture = myTexture; // Grab a reference to some texture we created earlier.
FileUtil.ReplaceFile (
AssetDatabase.GetAssetPath (texture), // Get current file path with extension.
toPath + Path.GetFileName(AssetDatabase.GetAssetPath (texture)) // The folder to place the new file.
);
myTexture = Resources.Load<Texture2D>(m_resourceFolder + "/" + texture.name); // Try to load the copied file.
When I run the above, I notice that the output for myTexture is null due to the copy not being created immediately, I must run it twice, or call that last line some time in the future then it works as expected.
How do I create a copy of a file and then reference that copy immediately?
Thanks.