Finding class where current GameObject is assigned to as a var

Hi gang,

Working with many class instances, my question:

Can a GameObject whose transform belongs to a class find that class in a simple “transform.myClass = what” kind of way?

i.e. class abcTest {var testObj : Transform;} with a script on the testObj assignment figuring out the exact instance of class abcTest it’s testObj transform belongs to.

Looking through an array works, but is rather cumbersome.

My current workaround is upon instantiating a prefab to testObj’s slot to pass a variable which stores the class it belongs to so it can access it form it’s own script, but was wondering if there is a better way.

Much appreciated!


I don’t quite understand your question. An object can have references from several different places- any given object has no way of knowing what other objects are referring to it. For example, you could have two classes-

class Foo 
    var someTrans : Transform;

class Bar
    var otherTrans : Transform;

Then, in your final class

class FooBar
    var bluh : Foo;
    var hulb : Bar;

if you go

bluh.someTrans = transform;


hulb.otherTrans = bluh.someTrans;

both of those objects have transform variables that refer to the same object!

So, as you can see there is no logical way for an object to definitively know what objects it is a member of, because a single object can be referred to from several different places.