Scriptableobject event parameter
[System.Serializable]
public class EventGameObject : UnityEvent<GameObject> { }
[CreateAssetMenu]
public class GameObjectEvent : ScriptableObject
{
private readonly List<GameObjectEventListener> eventListeners =
new List<GameObjectEventListener>();
public void Raise(GameObject go)
{
for (int i = eventListeners.Count - 1; i >= 0; i--)
eventListeners[i].OnEventRaised(go);
}
public void RegisterListener(GameObjectEventListener listener)
{
if (!eventListeners.Contains(listener))
eventListeners.Add(listener);
}
public void UnregisterListener(GameObjectEventListener listener)
{
if (eventListeners.Contains(listener))
eventListeners.Remove(listener);
}
}
public class GameObjectEventListener : MonoBehaviour
{
[Tooltip("Event to register with.")]
public GameObjectEvent Event;
[Tooltip("Response to invoke when Event is raised.")]
public EventGameObject Response;
private void OnEnable()
{
Event.RegisterListener(this);
}
private void OnDisable()
{
Event.UnregisterListener(this);
}
public void OnEventRaised(GameObject go)
{
Response.Invoke(go);
}
}
public class AIController : MonoBehaviour
{
public EventGameObject OnAIDeath;
private void Start()
{
OnAIDeath.Invoke(gameObject);
}
}
public class SceneMapController : MonoBehaviour
{
public void OnAIDeath(GameObject entityGO)
{
Debug.Log(entityGO);
}
}
GameObjectEventListener is on a SceneManager gameobject , when I drag the Scriptableobject Event on the event slot i want to use as listener SceneMapController script and run method OnAiDeath using the gameobject parameter from AIController invoke(gameObject) (check image)
What I'm doing wrong?I get this error please help Unsupported type EventGameObject https://imgur.com/a/ZhIqiWG
I'm having a similar problem. The value passed in script to Invoke()
doesn't carry through the event. Unity seems to only use the GameObject
assigned to the EventListener
in the Inspector.
Your answer
Follow this Question
Related Questions
Way to assign event fields in created at runtime scriptable object (ScriptableObject Architecture) 0 Answers
How to log the GameObject from a Scriptable Object Event 0 Answers
Why is Select image Dialog empty when trying to populate ScriptableObject? 0 Answers
Scriptable Objects inside other SO's not loading properly from Asset Bundle 1 Answer