Search Unity

Cannot create asset.

Discussion in 'Scripting' started by Lindennolet, Feb 28, 2022.

  1. Lindennolet

    Lindennolet

    Joined:
    Feb 16, 2022
    Posts:
    9
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEditor.SceneTemplate;
    5. using UnityEngine.SceneManagement;
    6.  
    7. public class NewBehaviourScript : MonoBehaviour
    8. {
    9.     public string test = "hello";
    10.     // Start is called before the first frame update
    11.     void Start()
    12.     {
    13.         SceneTemplateService.CreateSceneTemplate(test);
    14.     }
    15. }

    That's my script, I append it to a cube, press play and I get this error message:
    Code (CSharp):
    1. UnityException: Creating asset at path champ failed.
    2. UnityEditor.SceneTemplate.SceneTemplateService.CreateTemplateFromScene (UnityEditor.SceneAsset sourceSceneAsset, System.String sceneTemplatePath, UnityEditor.SceneTemplate.SceneTemplateAnalytics+TemplateCreationType creationType) (at <49dd6fba630a4485a2d84fe09bd6a4a6>:0)
    3. UnityEditor.SceneTemplate.SceneTemplateService.CreateSceneTemplate (System.String sceneTemplatePath) (at <49dd6fba630a4485a2d84fe09bd6a4a6>:0)
    4. NewBehaviourScript.Start () (at Assets/Scenes/NewBehaviourScript.cs:13)
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    Never used this API but pretty much every other editor asset creation API in Unity requires that you tell it the full path, which would probably be prefixed with
    "Assets/"
    and suffixed with
    ".unity"


    Did you try using a string such as
    "Assets/FoobarDoodle.unity
    ?