Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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
1
Question by buzz.burrowes · Jul 25, 2015 at 03:57 PM · componentinstancecopypaste

Copy / Paste As New not copying deep

I've got this class...

   [System.Serializable]   
   public class LoopConfig 
   {
      public AudioClip Clip = null;
      public AnimationCurve Envelope = new AnimationCurve();
      public float Gain = 1.0f;
   }

I've got this other class that contains one of those...

    public class CrossfadedLoopConfig : ScriptableObject
    {
       public LoopConfig LoopSettings = null;
       public AnimationCurve Fader = new AnimationCurve();
    }

I;ve got this MonoBehaviour...

    public class LoopCrossfader : MonoBehaviour
    {
       public float Gain = 1.0f;
       public float XFadePosition = 0.0f;
       
       public List<CrossfadedLoopConfig> LooperSettings = new List<CrossfadedLoopConfig>();
 
       void Start()
       {
          ... 
       }
 
       blah, blah, blah
    }

I've got a custom editor for this component, and it works great. Here is my problem...

If I right click on the component's name and select "Copy Component", and then right click again on the component's name and select "Past Component as New"... I don't get a deep copy.

The new (pasted) component's list of looper settings "points to" the original component's looper settings. So, here is an example...

If I have an instance of this component with 2 items in the LooperSettings list, and I copy and paste, and then I edit the first item in the original component instance's list of looper settings, I see those changes in the pasted component instance as well.

So... is there any way for me to get the paste to do a deep copy?

Thanks, Buzz

Comment
Add comment · Show 2
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 HypothicEntropy · Oct 29, 2015 at 03:52 PM 0
Share

I am currently trying to figure out the solution to this problem as well. Changing the values of a copied/pasted component changes the values on the other component which means they are pointing to the same variables rather than creating new one - which you would expect it would do when using 'paste component as new'.

avatar image callen · Jan 08, 2016 at 06:52 PM 0
Share

Would it make sense for you to convert the CrossfadedLoopConfig class to $$anonymous$$onoBehavior, and attach it to the same object which has the LoopCrossfader? If you did this, duplicating the game object ins$$anonymous$$d of the component will give you duplicates of each config component.

What you're really asking is why won't Unity create new CrossfadedLoopConfigs for you when you paste the component values. The reason is because the values aren't "part of" the LoopCrossfader component, only the references are (and those are what gets copied).

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Wanzyee · Jan 08, 2016 at 06:04 PM

Maybe, you can create a new list from the original one in script.

 void Awake(){
     LooperSettings = new List<CrossfadedLoopConfig>(LooperSettings);
 }

Try to do that when Awake. it's called after the new MonoBehaviour being instantiated, just make sure the GameObject active. Or, implement ISerializationCallbackReceiver with OnAfterDeserialize.

Comment
Add comment · 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

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

6 People are following this question.

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

Related Questions

What happens when i Copy an object (From Programming point of view) 1 Answer

Copy Paste multiple Texture2d's Into New Texture2d 1 Answer

Copy Material 1 Answer

Overriding Component Copy/Paste 2 Answers

Copying a Component's values without a new Game Object 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