AssetDatabase.CreateAsset creates 2 copy instead of 1

Hello everyone,

I have a problem
This creates 2 copy of my sciptableObject

    public static void CreateRandomWeapon()
    {
        WeaponData example = ScriptableObject.CreateInstance<WeaponData>();
        example.id = GUID.Generate().ToString();
        AssetDatabase.CreateAsset(example, ("Assets/Resources/Weapon/" + example.id + ".asset"));
    }

But i don’t understand why, for exemple this creates only 1 copy :

public static void CreateRandomWeapon()
    {
WeaponData example = ScriptableObject.CreateInstance<WeaponData>();
        example.id = GUID.Generate().ToString();
        AssetDatabase.CreateAsset(example, ("Assets/Resources/Weapon/venbvejbvjebve.asset"));

My problem is that i want to create an unique path with an unique name like in the first exemple

It’s a method, you probably call it twice somewhere?

In both case i call it 1 time. And in both case only the path in createAsset change.

I tried also this to be sure, it creates 2 differents copies :

 public int variable;

    private void Start()
    {
        variable = 0;
    }

    void Update()
    {
        if (Input.GetKeyDown("space"))
        {
            if (variable == 0)
            {
                CreateRandomWeapon();
                variable = 1;
            }
        }
    }

    public static void CreateRandomWeapon()
    {
        WeaponData example = ScriptableObject.CreateInstance<WeaponData>();
        string id1 = GUID.Generate().ToString();
        string id2 = id1 + ".asset";
        AssetDatabase.CreateAsset(example, ("Assets/Resources/Weapon/" + id2));

        Debug.Log("id1 : " + id1);
        Debug.Log("id2 : " + id2);
        Debug.Log("All : " + ("Assets/Resources/Weapon/" + id2));
    }

Something you’re doing. I tested it:
WeapoonData.cs

using UnityEngine;

public class WeaponData : ScriptableObject
{
    public string id;
}

Test.cs

using UnityEditor;
using UnityEngine;

public class Test : MonoBehaviour
{
    private void Awake() => CreateRandomWeapon();

    private static void CreateRandomWeapon()
    {
        var example = ScriptableObject.CreateInstance<WeaponData>();
        example.id = GUID.Generate().ToString();
        AssetDatabase.CreateAsset(example, ("Assets/Resources/Weapon/" + example.id + ".asset"));
    }
}

7561591--935455--screenshot.png

I think you have this script twice in your scene somewhere. I mean on two game objects and both run.

I restarted the computer and now it’s ok, i don’t have any explanation but it works well now