How to reference a GameObject from a UnityEvent that is located in a prefab?

In my case I am using a Unity Event Wrapper, which is in a 3rd party package (Oculus Interaction), that is supposed to call a method from the GameManager (My main management script) which is attached as a component to a GameObject in the hierarchy.
(Probably since the event wrapper is a part of a prefab) the GameManager cannot be referenced by the event wrapper (only scripts and prefabs are possible).

8902191--1218162--UnityEventWrapper.png

It might also be useful to say that it is not possible to get the GameManager instance in the Unity event wrapper code because it is “encapsulated” by an assembly definition.

Does anyone know how I can change my GameManager or use the Unity Event Wrapper differently to call the method?

Maybe something similar to this has happened to someone before.
I’m always willing to answer questions that provide a clearer picture of the problem.
Thanks for all the answers in advance!

It doesn’t make sense to call a method on a prefab asset or vice versa. The point of prefabs is to live in scenes so their respective objects/components can be referenced by their scene instances.

If you want to call some method irrespective of a scene, make it static (and maybe put it in a static class), or use scriptable objects.

1 Like