Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by dCalle · Aug 10, 2017 at 09:44 AM · editor-scriptingscriptableobjectcustom-inspectorreferencingcopy

Deep Copy of ScriptableObject

Hey, I know a similar topic is floating around in Answers, but it's some years old and doesn't work, at least for me...

So I want to copy a scriptableObject WITH its references... CopySerialized doesn't work as well as Instantiate... does not...

What am I doing wrong?

         internal static PersonalObject Personalise(this PersonalObject pObject, Object owner)
         {
             string newPath = CreateAssetDirectory(pObject.GetType(), owner);
             newPath = AssetDatabase.GenerateUniqueAssetPath(newPath + "/" + pObject.GetType().Name + ".asset");
 
             PersonalObject newObject = ScriptableObject.Instantiate(pObject) as PersonalObject;
             AssetDatabase.CreateAsset(newObject, newPath);
             EditorUtility.CopySerialized(pObject, newObject);
             newObject.isPersonalised = true;
             newObject.ownerID = owner.GetInstanceID();
             return newObject;
         }
 

I shuffled order in any way I could imagine, also used AssetDatabase.CopyAsset, nothing works. Is CopySerialized supposed to use the SerializedObject?

Thanks...

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Aug 13, 2017 at 02:09 PM

Serialized references will always stay references. The only exception are references to child objects when cloning gameobjects.

ScriptableObjects are assets. Assets can only reference other assets. So if you want a "true" deep copy it would have a quite heavy effect. For example when your scriptable object references other scriptable objects which might reference prefabs. A deep copy would require to also duplicate those "referenced" scriptableobjects as well. However since they are assets they need a new file name. However the referenced prefabs would also need to be duplicated. If the prefabs reference Meshes and materials those need to be duplicated as well. The Material will reference a shader and some textures which would be duplicated as well. I can't really imagine any situation where you need that.

In most cases you will have only some specific references you want to duplicate. In that case you have to duplicate those manually. Keep in mind that all assets need to be stored in some sort of asset file.

If that doesn't answer your question you should be more specific about what kind of references you talk about and what you mean by "deep copy".

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dCalle · Feb 26, 2018 at 02:38 PM 0
Share

well quite a while ago and i dug into other stuff, but still I can't even copy a string from one object to another...

what am i doing wrong? Apply$$anonymous$$odifiedProperties as well as serializedObject.Update() don't work.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

77 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I remove a ScriptableObject reference after the script has been deleted? 0 Answers

Create List of custom class types, for use in custom editor 0 Answers

[SOLVED] Custom editor can't acces to variables of a scriptable object 1 Answer

Reorderable list of UnityEvents 2 Answers

Implementing a 2D array as a field on a ScriptableObject? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges