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
0
Question by Jix · Nov 09, 2013 at 01:14 AM · editorreferenceadvanced

How to detect if a game object is referenced in an unknown script

Ok, here's a tough question. I'm making an editor script and I will be destroying game objects and replace them with new game objects, my problem is that the old objects may be referenced in some scripts and I need the scripts to reference the new objects.

Here's what you need to know to provide an answer

1- I don't know which objects in the scene will be destroyed and replaced with a new one. And that means that I don't know which scripts I need to change their references.

2- I'm doing this in Editor time, the game is not running and I have some experience in Editor scripting

3- What I exactly need is a way to get an array of all references referring to a specific game object... is it even possible?

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 ThePunisher · Nov 09, 2013 at 01:51 AM 0
Share

How do you not know what objects are being destroyed? At some point some script has to get a hold of the object you are destroying? Right? What is the overall goal you are trying to achieve? Perhaps you're going about it the wrong way.

avatar image Jix · Nov 09, 2013 at 02:00 AM 0
Share

I'm making a script that will replace Objects in Editor time, I don't know which Object the user will replace... so I have no idea if he has made a reference to this object he's replacing. Of course my script will catch a reference of the object before destroying it but what about any reference in the scene referring to it? they will all be null

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Aspirer · Nov 09, 2013 at 01:52 AM

It would depend... I would say if you're going to be doing this via mouse, have your game-controller with an OnMouseDown call that draws a ray from the point of the click, in the direction the camera is facing (which should make a collision with whatever you're clicking on. It should be a GameObject. Then, I would assume something like

 Destroy(HitCastInfo.collider.gameObject);
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 Jix · Nov 09, 2013 at 01:56 AM 0
Share

That's not what I'm asking for

I want to know if a specific game object is referenced in another script... any script.

And I'm doing this in Editor not in play time

avatar image Aspirer · Nov 09, 2013 at 04:26 AM 0
Share

OH! Totally misread the question. $$anonymous$$y apologies.

avatar image Jix · Nov 09, 2013 at 05:35 AM 0
Share

hehe... no problem

avatar image
0

Answer by Serinx · Feb 15, 2021 at 03:53 AM

Bit of a necro, but I couldn't find an answer this question and ended up doing the following to figure it out. It's very long winded but fine to do if you only have to check a couple of references.

  1. Copy the name of the gameobject you want to find the references for i.e. "BossSpawnpoint" (you might have to rename it if it's not unique).

  2. Open the scene in file explorer using notepad

  3. Ctrl+F Search for your "BossSpawnpoint"

  4. You should find m_Name: BossSpawnpoint in the file. Slightly above should be something like this - component: {fileID: 1587079324}

  5. Copy that ID and search for it - you should find that id referenced in another gameobject.

  6. Scroll up a bit you should find the "GameObject:" tag and then a "m_Name:" which tells you the name of the GameObject which references your first gameobject e.g. "m_Name: BossSpawner"

Hope that helps someone! If anyone knows a better way, please let me 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

19 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

Related Questions

Reference a script from Editor folder 2 Answers

The ‘ContextClick’ event of the ‘TreeView’ class does not fire from a custom inspector; but if you do it from an editor window it fires. 0 Answers

How can I get the name of a class into a script from the editor. 1 Answer

Setting a reference to a Singleton in the editor not possible? 1 Answer

Parent losing references to Child fields after duplication, copy/paste 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