Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

(Question)how do ScriptableObject can deep copy during runtime?

Discussion in 'Scripting' started by bbsuuo, Mar 8, 2019.

  1. bbsuuo

    bbsuuo

    Joined:
    Jul 21, 2016
    Posts:
    16
    嗨,我正在创建一个AI行为树节点编辑器系统,我创建一个新的生命周期类来运行AI逻辑函数和它的继承ScriptableObject , 但它不能在多个GameObject中工作,所以我想 在运行时在内存中复制资产和重新分配。

    我尝试使用“Object.Instantiate”来创建实例。但实例的引用子类是本地资产的子类。

    所以有任何功能可以轻松实例化所有资产包括子类并保持参考?
     
  2. DeeJayVee

    DeeJayVee

    Joined:
    Jan 2, 2015
    Posts:
    121

    Could you not instantiate the GameObject to a list? Would that work?

    你能否将GameObject实例化为一个列表?那会有用吗?


    Code (CSharp):
    1. List<"ScriptableObjectName"> objectList = new List<"ScriptableObjectName">;
    2.  
    3.  
    4. void InstantiateObjectToList()
    5. {
    6. objectList.Add(GameObject.Instantiate("ScriptableObject");
    7. }
     
  3. bbsuuo

    bbsuuo

    Joined:
    Jul 21, 2016
    Posts:
    16
    no , Their references point to local asset , so i must reassign their references , and it's to trouble
     
  4. DeeJayVee

    DeeJayVee

    Joined:
    Jan 2, 2015
    Posts:
    121
    I understand, hopefully someone can help you then. Good luck.
     
  5. bbsuuo

    bbsuuo

    Joined:
    Jul 21, 2016
    Posts:
    16
    anybody help me