Editor.target vs Editor.serializedObject2019 Community Moderator ElectionStill can't make Escape key to quit game even in Standalone mode. How can i solve it?Dynamically creating a CustomEditor class in Unity / C#Unity Custom Inspector with sub-inspectorsUsing C# Attributes, how would I trigger functions to be executed on change of their assigned fieldIs there a way to stretch a RenderTexture playing on a plane with a VideoPlayer in Unity?How to handle touch selection on Unity3D using LeanTouch free asset?

If nine coins are tossed, what is the probability that the number of heads is even?

Generating a list with duplicate entries

Inorganic chemistry handbook with reaction lists

How to recover against Snake as a heavyweight character?

Does an unused member variable take up memory?

Too soon for a plot twist?

Short story about cities being connected by a conveyor belt

What is the oldest European royal house?

Professor forcing me to attend a conference, I can't afford even with 50% funding

After Brexit, will the EU recognize British passports that are valid for more than ten years?

Is divide-by-zero a security vulnerability?

Is there a math expression equivalent to the conditional ternary operator?

How does learning spells work when leveling a multiclass character?

What can I do if someone tampers with my SSH public key?

Why do we call complex numbers “numbers” but we don’t consider 2-vectors numbers?

Why isn't P and P/poly trivially the same?

ESPP--any reason not to go all in?

Where is the License file location for Identity Server in Sitecore 9.1?

What does *dead* mean in *What do you mean, dead?*?

Is there a logarithm base for which the logarithm becomes an identity function?

Is the differential, dp, exact or not?

What do you call someone who likes to pick fights?

Short SF story. Females use stingers to implant eggs in yearfathers

Does the US political system, in principle, allow for a no-party system?



Editor.target vs Editor.serializedObject



2019 Community Moderator ElectionStill can't make Escape key to quit game even in Standalone mode. How can i solve it?Dynamically creating a CustomEditor class in Unity / C#Unity Custom Inspector with sub-inspectorsUsing C# Attributes, how would I trigger functions to be executed on change of their assigned fieldIs there a way to stretch a RenderTexture playing on a plane with a VideoPlayer in Unity?How to handle touch selection on Unity3D using LeanTouch free asset?










1















So I have this simple script:



using UnityEngine;

public class MyScript: MonoBehaviour

public int damage = 25;

public void PrintStuff()

Debug.Log("Stuff");




And this CustomEditor where I use Editor.serializedObject:



using UnityEngine;
using UnityEditor;

[CustomEditor(typeof(MyScript))]
public class LookAtPointEditor : Editor

SerializedProperty damageProp;

void OnEnable()

// Setup the SerializedProperties.
damageProp = serializedObject.FindProperty("damage");


public override void OnInspectorGUI()

serializedObject.Update();

EditorGUILayout.IntSlider(damageProp, 0, 100, new GUIContent("Damage"));

serializedObject.ApplyModifiedProperties();





This works fine: Undo thing works, exiting out of Play Mode works but I can do the same thing using Editor.target and a lot easier. And all functionality works fine with Editor.target. What is the purpose of serializedObject then?










share|improve this question


























    1















    So I have this simple script:



    using UnityEngine;

    public class MyScript: MonoBehaviour

    public int damage = 25;

    public void PrintStuff()

    Debug.Log("Stuff");




    And this CustomEditor where I use Editor.serializedObject:



    using UnityEngine;
    using UnityEditor;

    [CustomEditor(typeof(MyScript))]
    public class LookAtPointEditor : Editor

    SerializedProperty damageProp;

    void OnEnable()

    // Setup the SerializedProperties.
    damageProp = serializedObject.FindProperty("damage");


    public override void OnInspectorGUI()

    serializedObject.Update();

    EditorGUILayout.IntSlider(damageProp, 0, 100, new GUIContent("Damage"));

    serializedObject.ApplyModifiedProperties();





    This works fine: Undo thing works, exiting out of Play Mode works but I can do the same thing using Editor.target and a lot easier. And all functionality works fine with Editor.target. What is the purpose of serializedObject then?










    share|improve this question
























      1












      1








      1








      So I have this simple script:



      using UnityEngine;

      public class MyScript: MonoBehaviour

      public int damage = 25;

      public void PrintStuff()

      Debug.Log("Stuff");




      And this CustomEditor where I use Editor.serializedObject:



      using UnityEngine;
      using UnityEditor;

      [CustomEditor(typeof(MyScript))]
      public class LookAtPointEditor : Editor

      SerializedProperty damageProp;

      void OnEnable()

      // Setup the SerializedProperties.
      damageProp = serializedObject.FindProperty("damage");


      public override void OnInspectorGUI()

      serializedObject.Update();

      EditorGUILayout.IntSlider(damageProp, 0, 100, new GUIContent("Damage"));

      serializedObject.ApplyModifiedProperties();





      This works fine: Undo thing works, exiting out of Play Mode works but I can do the same thing using Editor.target and a lot easier. And all functionality works fine with Editor.target. What is the purpose of serializedObject then?










      share|improve this question














      So I have this simple script:



      using UnityEngine;

      public class MyScript: MonoBehaviour

      public int damage = 25;

      public void PrintStuff()

      Debug.Log("Stuff");




      And this CustomEditor where I use Editor.serializedObject:



      using UnityEngine;
      using UnityEditor;

      [CustomEditor(typeof(MyScript))]
      public class LookAtPointEditor : Editor

      SerializedProperty damageProp;

      void OnEnable()

      // Setup the SerializedProperties.
      damageProp = serializedObject.FindProperty("damage");


      public override void OnInspectorGUI()

      serializedObject.Update();

      EditorGUILayout.IntSlider(damageProp, 0, 100, new GUIContent("Damage"));

      serializedObject.ApplyModifiedProperties();





      This works fine: Undo thing works, exiting out of Play Mode works but I can do the same thing using Editor.target and a lot easier. And all functionality works fine with Editor.target. What is the purpose of serializedObject then?







      unity3d






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 2 days ago









      Petro KovalPetro Koval

      18510




      18510






















          1 Answer
          1






          active

          oldest

          votes


















          2














          Good question! The Editor API docs explains this but the info is mostly scattered so I'll summarize:



          For starters, there's an option CanEditMultipleObjects which you're currently not using. A quote form the docs:




          If this approach is used a user can select multiple assets in the
          hierarchy window and change the values for all of them at once.




          For a basic example of this, select two GameObjects in your scene that have the same Unity component (like Image or Rigidbody) and you'll be able to modify those components at the same time to have the same values. Most built-in components support it.



          This is the first advantage using serializedObject will give you; it supports multi-object editing and Editor.target does not (you'd need Editor.targets for that). So now if you're wondering, "why wouldn't I just use Editor.targets for multi-object editing?" consider this quote from the docs:




          Instead of modifying script variables directly, it's advantageous to
          use the SerializedObject and SerializedProperty system to edit them,
          since this automatically handles multi-object editing, undo, and
          Prefab overrides
          .




          What this boils down to is that if you don't want undo, prefab override, and multi-object-editing features to be automatically handled for you, just use Editor.target or Editor.targets. If you do want those features to just work automatically, use SerializedObject and SerializedProperty.






          share|improve this answer

























          • @PetroKoval and undo, and prefab overrides, no?

            – DMGregory
            2 days ago










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55027410%2feditor-target-vs-editor-serializedobject%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          Good question! The Editor API docs explains this but the info is mostly scattered so I'll summarize:



          For starters, there's an option CanEditMultipleObjects which you're currently not using. A quote form the docs:




          If this approach is used a user can select multiple assets in the
          hierarchy window and change the values for all of them at once.




          For a basic example of this, select two GameObjects in your scene that have the same Unity component (like Image or Rigidbody) and you'll be able to modify those components at the same time to have the same values. Most built-in components support it.



          This is the first advantage using serializedObject will give you; it supports multi-object editing and Editor.target does not (you'd need Editor.targets for that). So now if you're wondering, "why wouldn't I just use Editor.targets for multi-object editing?" consider this quote from the docs:




          Instead of modifying script variables directly, it's advantageous to
          use the SerializedObject and SerializedProperty system to edit them,
          since this automatically handles multi-object editing, undo, and
          Prefab overrides
          .




          What this boils down to is that if you don't want undo, prefab override, and multi-object-editing features to be automatically handled for you, just use Editor.target or Editor.targets. If you do want those features to just work automatically, use SerializedObject and SerializedProperty.






          share|improve this answer

























          • @PetroKoval and undo, and prefab overrides, no?

            – DMGregory
            2 days ago















          2














          Good question! The Editor API docs explains this but the info is mostly scattered so I'll summarize:



          For starters, there's an option CanEditMultipleObjects which you're currently not using. A quote form the docs:




          If this approach is used a user can select multiple assets in the
          hierarchy window and change the values for all of them at once.




          For a basic example of this, select two GameObjects in your scene that have the same Unity component (like Image or Rigidbody) and you'll be able to modify those components at the same time to have the same values. Most built-in components support it.



          This is the first advantage using serializedObject will give you; it supports multi-object editing and Editor.target does not (you'd need Editor.targets for that). So now if you're wondering, "why wouldn't I just use Editor.targets for multi-object editing?" consider this quote from the docs:




          Instead of modifying script variables directly, it's advantageous to
          use the SerializedObject and SerializedProperty system to edit them,
          since this automatically handles multi-object editing, undo, and
          Prefab overrides
          .




          What this boils down to is that if you don't want undo, prefab override, and multi-object-editing features to be automatically handled for you, just use Editor.target or Editor.targets. If you do want those features to just work automatically, use SerializedObject and SerializedProperty.






          share|improve this answer

























          • @PetroKoval and undo, and prefab overrides, no?

            – DMGregory
            2 days ago













          2












          2








          2







          Good question! The Editor API docs explains this but the info is mostly scattered so I'll summarize:



          For starters, there's an option CanEditMultipleObjects which you're currently not using. A quote form the docs:




          If this approach is used a user can select multiple assets in the
          hierarchy window and change the values for all of them at once.




          For a basic example of this, select two GameObjects in your scene that have the same Unity component (like Image or Rigidbody) and you'll be able to modify those components at the same time to have the same values. Most built-in components support it.



          This is the first advantage using serializedObject will give you; it supports multi-object editing and Editor.target does not (you'd need Editor.targets for that). So now if you're wondering, "why wouldn't I just use Editor.targets for multi-object editing?" consider this quote from the docs:




          Instead of modifying script variables directly, it's advantageous to
          use the SerializedObject and SerializedProperty system to edit them,
          since this automatically handles multi-object editing, undo, and
          Prefab overrides
          .




          What this boils down to is that if you don't want undo, prefab override, and multi-object-editing features to be automatically handled for you, just use Editor.target or Editor.targets. If you do want those features to just work automatically, use SerializedObject and SerializedProperty.






          share|improve this answer















          Good question! The Editor API docs explains this but the info is mostly scattered so I'll summarize:



          For starters, there's an option CanEditMultipleObjects which you're currently not using. A quote form the docs:




          If this approach is used a user can select multiple assets in the
          hierarchy window and change the values for all of them at once.




          For a basic example of this, select two GameObjects in your scene that have the same Unity component (like Image or Rigidbody) and you'll be able to modify those components at the same time to have the same values. Most built-in components support it.



          This is the first advantage using serializedObject will give you; it supports multi-object editing and Editor.target does not (you'd need Editor.targets for that). So now if you're wondering, "why wouldn't I just use Editor.targets for multi-object editing?" consider this quote from the docs:




          Instead of modifying script variables directly, it's advantageous to
          use the SerializedObject and SerializedProperty system to edit them,
          since this automatically handles multi-object editing, undo, and
          Prefab overrides
          .




          What this boils down to is that if you don't want undo, prefab override, and multi-object-editing features to be automatically handled for you, just use Editor.target or Editor.targets. If you do want those features to just work automatically, use SerializedObject and SerializedProperty.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 2 days ago

























          answered 2 days ago









          FoggzieFoggzie

          7,50612443




          7,50612443












          • @PetroKoval and undo, and prefab overrides, no?

            – DMGregory
            2 days ago

















          • @PetroKoval and undo, and prefab overrides, no?

            – DMGregory
            2 days ago
















          @PetroKoval and undo, and prefab overrides, no?

          – DMGregory
          2 days ago





          @PetroKoval and undo, and prefab overrides, no?

          – DMGregory
          2 days ago



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55027410%2feditor-target-vs-editor-serializedobject%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

          2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme