Search Unity

Turning assets into scripts creating global namespace overlap

Discussion in 'Scripting' started by Avian_Overlord, Aug 1, 2018.

  1. Avian_Overlord

    Avian_Overlord

    Joined:
    Dec 27, 2015
    Posts:
    34
    Okay, this is a bit tricky. I've converting my SpawnerTypes (a base class with a number of inheritors) into assets using this script:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.IO;
    4. using System;
    5. using UnityEditor;
    6.  
    7. public class ProcStatic : MonoBehaviour {
    8.  
    9.     [MenuItem("Edit/Regenerate All SpawnerTypes")]
    10.     public static void RegenerateAllSpawnerTypes()
    11.     {
    12.         string path = Application.dataPath + "/Procedural/SpawnerTypes/";
    13.         string[] typesFull = Directory.GetFiles(path);
    14.  
    15.         int x = 0;
    16.         foreach (string str in typesFull)
    17.         {
    18.             string filename = str.Substring(str.LastIndexOf("/") + 1);
    19.  
    20.             if (filename.EndsWith(".cs"))
    21.             {
    22.                 string meh = filename.Remove(filename.Length - 3);
    23.  
    24.                 var spawnerType = meh;
    25.                 var spawn = ScriptableObject.CreateInstance(spawnerType);
    26.                 AssetDatabase.CreateAsset(spawn, "Assets/SpawnerTypes/" + spawnerType + ".asset");
    27.                 AssetDatabase.SaveAssets();
    28.  
    29.                 Debug.Log(meh);
    30.                 x++;
    31.             }
    32.  
    33.         }
    34.     }
    35.  
    36. }
    (Based on code I found searching the forum)
    However, this is giving me the error message "The namespace `global::' already contains a definition for `TestSpawner'" Anyone know how to fix this?
     
  2. FlashMuller

    FlashMuller

    Joined:
    Sep 25, 2013
    Posts:
    451
    Are you trying to overwrite the old Assets and therefor at some point have duplicated types? Basically it means that there is already a class thats called TestSpawner, nothing else.
     
  3. Avian_Overlord

    Avian_Overlord

    Joined:
    Dec 27, 2015
    Posts:
    34
    Yeah, I had two copies of TestSpawner in different folders. Simple enough.