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
6
Question by Baroque · May 10, 2017 at 02:26 AM · editorselectiondocumentation

What is Selection.SetActiveObjectWithContext for?

UnityEditor.Selection has a function SetActiveObjectWithContext() and a counterpart field activeContext.

What is this for? The documentation is not exactly forthcoming.

Comment
Add comment · Show 1
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 armorhide406 · May 10, 2017 at 03:11 AM 0
Share

I would imagine it has to do with context in the respect of lighting https://docs.unity3d.com/$$anonymous$$anual/StandardShaderContextAndContent.html

I'm not sure though

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by inferno222 · Sep 28, 2017 at 10:26 AM

I found out you can use it to select scriptable objects with it, which can't be done directly with Selection.activeGameObject because it requires a gameObject.

For example: Selection.SetActiveObjectWithContext(Your_Scriptable_Object, null);

It will be nice to know what the context is used for.

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
1

Answer by codestage · Nov 28, 2017 at 09:42 PM

Docs are pretty empty for this, yeah =(
My guess: it just allows to store some additional object in current selection for more flexibility.
E.g. you could wish to select some object and store its parent or other dependency or any other related Unity object as context for further usage.

@inferno222 for non-GameObject selection there is another property:
Selection.activeObject and it can be freely used without Selection.SetActiveObjectWithContext() usage.

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
1

Answer by Bunny83 · Sep 11, 2018 at 12:51 PM

Since the question got bumped already


The point of the context is to provide additional information that is not part of the selected object. So it could be a ScriptableObject instance that gives more information about the selected "thing". Of course its use is context specific.


Imagine you have a ScriptableObject or MonoBehaviour that has an array of strings. If you need in some custom editor to select one of those strings you could reference the scriptableobject / MonoBehaviour as the selected object and create a special ScriptableObject instance that holds the information about the index which string you actually meant. Keep in mind that the Selection class is the main link between different editor tools.

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 Romeno · Apr 15, 2019 at 10:06 PM 0
Share

How do you use that info? Is there a callback for this?

avatar image Bunny83 Romeno · Apr 16, 2019 at 12:19 AM 0
Share

Have you actually looked at the Selection class documentation? If so the very first property it has is the activeContext. There you access the context if one has been set. The only callback that the Selection class provides is the selectionChanged delegate.

avatar image
0

Answer by Bill-Sansky · Sep 11, 2018 at 11:49 AM

More information for those coming here late: The difference between

Selection.activeObject = obj;

and

Selection.SetActiveObjectWithContext(obj, obj);

is that the second one will also change Selection.objects to be only the active object: always good to know!

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

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

Related Questions

Hierarchy Foldout Variables Wanted 3 Answers

Force select object in hierarchy via editor script? 1 Answer

Standard Model Problems- after upgrade to 5.6.1 2 Answers

Is there a way to document/leave notes on gameobjects without attaching a component to the gameobject (which adds overhead) 1 Answer

How can I get info on object in scene view without selecting it? 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