Hello. I’d like to write an editorWindow script for building my project. What I want to do is :
- move my “Assets/Resources/Paris” folder to “Assets/Temp/Paris” folder
- build
- move “Assets/Temp/Paris” to “Assets/Resources/Paris”
- delete “Assets/Temp/Paris”
I move my folder with “FileUtil.MoveFileOrDirectory” but how do I know when the move is finished so I can build ?
(Sorry if my subject has already been posted and sorry If my english is bad)
Thank you !
I’m going to bet it blocks until the action is complete.
Usually a method blocks until complete. If it does something that returns immediately before complete it’ll do so as an asynchronous call and return some token that could be used to check for completion.
Of course… this isn’t a 100% guarantee… but I’m fairly certain Unity wouldn’t have broken that common practice.
Actually… my script is :
FileUtil.MoveFileOrDirectory(“Assets/Resources/Paris”, “Assets/Temp/Paris”);
Debug.Log(“log”);
And when it plays, the log is printed immediately but my folder in my hierarchy is not mooved yet…
Edit : But maybe the folder does moove but my project hierarchy does not update.
Well, I’m going to assume you’re most likely calling this method during the OnGUI event in some way (or in some function called during the OnGUI event).
So yeah, the screen wouldn’t update until the next OnGUI event. Which would be after your Debug.Log.
But when I play my build it seems that the Resources/Paris folder did not moove !
I can confirm that it does not update the hierarchy very quickly.
I made a similar log after the move call and noticed the file had not moved in the hierarchy. I went to the prior folder to make sure it wasn’t there. Went back. Still hadn’t moved.
I then searched for a solution and found this forum post. Now when I go back to the hierarchy I can confirm that it did indeed move. It seems that clicking off of Unity and back onto Unity is forcing it to refresh the folder structure.
I just ran a second test with two FileExplorer windows open showing each folder. It moved in roughly a second.
Call this after the move:
AssetDatabase.Refresh();