Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Jessy · Dec 03, 2009 at 09:13 PM · editor-scripting

What is EditorUtility.CopySerialized supposed to do?

If I, for example, use this function with the parameters of

  1. the default Game Object in a Unity Scene, the "Main Camera"

and

  1. an empty Game Object

then "Game Object" will be renamed "Main Camera", but lose all of its components, including its Transform.

This can't be the intended use! So what is?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Jaap Kreijkamp · Dec 04, 2009 at 01:09 AM

You need to use it on all components as well, but in my experience this results in crashing Unity. You can use it however to clone script settings to a new object. For example the script below copies the properties from JDiceSideUp script in object dice to (existing) object newDice (if script isn't there yet it will be added).

using UnityEngine;

using UnityEditor; using System.Collections;

public class JTestEditorClass {

 [MenuItem("Ctrl-J/Set Script Properties")]
 static void TestCopy() {
     GameObject orig = (GameObject) GameObject.Find("dice");
     GameObject modify = (GameObject) GameObject.Find("newdice");

     Component fromScript = orig.GetComponent(typeof(JDiceSideUp));
     Component toScript = orig.GetComponent(typeof(JDiceSideUp));
     if (toScript == null) {
             toScript = go.AddComponent(fromScript.GetType());
     }
     EditorUtility.CopySerialized(fromScript, toScript);
 }

}

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
avatar image
0

Answer by Jessy · Dec 11, 2009 at 03:37 AM

(First off, I apologize for not putting this in the comments, but UnityAnswers provides no functionality that I can see for a lengthy response, or one that includes code.) :-P

Thanks, but there is some kind of serious problem here. Using the simpler case from above, I believe the resulting script is this:

using UnityEngine; using UnityEditor;

public class JTestEditorClass {

[MenuItem("Ctrl-J/Set Script Properties")] static void TestCopy() { Component mainCamera = GameObject.Find("Main Camera").GetComponent( typeof(Camera) ); EditorUtility.CopySerialized ( mainCamera, GameObject.Find("Game Object").AddComponent( mainCamera.GetType() ) ); }

}

However, after doing that, it is impossible to remove the Camera component from the previously empty Game Object. This error also occurs:

referencedGO != this

Now what?

Comment
Add comment · Show 2 · 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 Jaap Kreijkamp · Dec 11, 2009 at 05:56 AM 0
Share

As I said, CopySerialized seems to be buggy and crashes my environment often. It does work okay on scripts so you can use it to safely copy the script data. But other than that, I'd say CopySerialized is a bugreport worthy. As I'm plagued by so many bugs in Unity I've stopped reporting them, if project pressure drops I'll go and file a book full.

avatar image Jessy · Dec 11, 2009 at 06:36 AM 0
Share

Well, that's good enough for me. You answered what it's "supposed" to do, even if it doesn't do a very good job. Thanks again.

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

No one has followed this question yet.

Related Questions

Updating object on inspector value changes in editor 1 Answer

Creating graphs with nodes and edges in the editor (diagrams) 1 Answer

EditorWindow visibility 0 Answers

Adding/removing objects in editor mode 1 Answer

How do I make a progress bar in the editor lock the background? 0 Answers


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