How to log the GameObject from a Scriptable Object Event
Hello,
I have an event system within a C# struct and some ScriptableObjects using it. One ScriptableObject class has a method with a Debug.Log call. This method has to be called by a GameObject referencing the ScriptableObject.
I want to debug the gameobject that called this method, but I don't know how to access any of its data from the Scriptable or the event system.
The Debug.Log stack trace is stopping at the Scriptable Object Level...
[my log message] UnityEngine.Debug:LogWarning (object) MyScriptableObjects:MyMethod (MyScriptableObjects) (at Assets/PathToMyScriptable.cs:15) System.Reflection.MethodBase:Invoke(object,object[]) MyCustomEventEntry:b__4_0 () (at Assets/PathToMyCustomEventEntry.cs:36).
...end of stack trace
But I know that MyScriptableObjects:MyMethod (MyScriptableObjects) is called from a GameObject, I want to know it's ID or any data from it within the Debug.Log, is it possible ?
Pseudo code would look like:
public class MyComponent : Monobehaviour
{
MyEvent events;
MyScriptableObject scriptable;
void Start()
{
events.Add(scriptable.MyMethod);
events.Invoke();
}
}
public struct MyEvent
{
List<MyEventEntry> entries;
public void Add(Action callback)
{
entries.Add(new MyEventEntry(callback));
}
public void Invoke()
{
foreach (var e : entries) e.Invoke();
}
}
public class MyScriptableObject : ScriptableObject
{
public void MyMethod()
{
Log(); // I want to log the gameobject here
}
}