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 andycodes · Dec 02, 2016 at 02:49 AM · selectioneditor scripting

how to print selected game object in editor to console?

I'm attempting to get into editor scripting but i haven't had any luck for the life of me. currently what i'm trying to accomplish is to have the console print out the name of the game object that has just been selected in the hierarchy or scene view. From what I've researched i assume I'll need the following snippet of code somewhere:

         print (Selection.activeGameObject.name);

but i cant seem to figure out how to get the code running up to that point. This code i made seems to make sense to me (and i've placed the script in an "Editor" folder in my project view) but it doesn't execute.

 using UnityEngine;
 using System.Collections;
 using UnityEditor;
 
 public class PrintObjectName : MonoBehaviour {
 
     void OnSelectionChange(){
         print (Selection.activeGameObject.name);
     }
 }


If anybody could at least get me going in the right direction that'd be a tremendous help!

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
0

Answer by Yoshinator2 · Dec 02, 2016 at 03:55 AM

This is done very simply by adding

  Debug.Log(Selection.activeGameObject.name);

Please accept this answer if this helped you. If you have any more questions feel free to ask. Cheers!

Comment
Add comment · Show 3 · 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 andycodes · Dec 02, 2016 at 04:06 AM 0
Share

Hi, Yoshinator2

Replacing print with Debug.Log still doesn't appear to log the name of the gameObject to my console. Am I using the correct function [OnSelectionChange()]? $$anonymous$$y scene currently only consists of a cube called "Test Cube" and no other scripts.

avatar image Yoshinator2 andycodes · Dec 02, 2016 at 04:09 AM 0
Share

Are you using a script for selection? Or are you physically clicking on it?

avatar image andycodes Yoshinator2 · Dec 02, 2016 at 04:11 AM 0
Share

its an editor script that's not actively in the scene but I want it to be called by the editor whenever any game object in the hierarchy or in the scene view is selected.

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

57 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

Related Questions

How to show an Editor Window based upon Selection 1 Answer

Why do I get error on the Selection.activeGameObject = gameObject? 2 Answers

Level selection from main menu? 4 Answers

"add selected" editor script 1 Answer

Editor scripting, select a field 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