- Home /
stackoverflow on editor script.
Hey guys, I can't figure out why I keep getting a stack over flow exception error.
I've tried multiple ways to get this to work but just can't seem to figure out what is causing it to recursively keep overflowing.
(What I am trying to do is, copy folders from a specific place into Unity project). Almost have it, but can't grasp the Stack Error because I don't see how it's constantly running, perhaps I just don't understand enough about what's going on. Hope you guys / gals can help, until then, I'll be trying to figure this out more.
Here is the code.
(Editor GUI Button to run code).
if (GUILayout.Button (FindRepo)) {
FindRepository();
ImportCulturalization(".", @".\temp", true);
//ImportCulturalization(FolderPath, @".\temp", true);
}
Now here is the actual code.
private void ImportCulturalization(string RepoFolder,string destinationFolder,bool copySubDirs){
string RepoFold = AssetDatabase.CreateFolder ("Codex-It", "Repository");
RepoFolder = FolderPath;
destinationFolder = RepoFold;
string CodexFolderPath = AssetDatabase.GUIDToAssetPath (destinationFolder);
// Here we import all the files if the Repository exists.
DirectoryInfo dir = new DirectoryInfo (RepoFolder);
if (!dir.Exists)
{
throw new DirectoryNotFoundException(
"Source Repository does not exist or could not be found: "
+ RepoFolder);
}
DirectoryInfo[] dirs = dir.GetDirectories();
// If the destination directory doesn't exist, create it.
if (Directory.Exists(destinationFolder))
{
Directory.CreateDirectory(destinationFolder);
}
FileInfo[] files = dir.GetFiles ();
foreach (FileInfo file in files) {
string tempP = Path.Combine(destinationFolder,file.Name);
file.CopyTo(tempP,false);
}
if (copySubDirs) {
foreach(DirectoryInfo subdir in dirs){
string tempD = Path.Combine(destinationFolder,subdir.Name);
ImportCulturalization(subdir.FullName,tempD,copySubDirs);
}
}
// I just added this to see if that helped - Nope.
copySubDirs = false;
}
Well I found the issue, but I don't get how I can change it,
where it says at the bottom if(copySubDirs){ ImportCulturalization - that's the error. }
However, it kind of needs to be there so it can copy all of the directories and place them into Unity.
Is there another way to go about doing this?