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?

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);

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!