Search Unity

UltEvents - The Ultimate Event System For The Ultimate Price - FREE

Discussion in 'Assets and Asset Store' started by Kybernetik, Jun 1, 2019.

  1. unity_8VnLFqABeZGQQQ

    unity_8VnLFqABeZGQQQ

    Joined:
    Aug 13, 2020
    Posts:
    3
    Is there a discord for your projects where I can get help?

    I'm trying to use Coroutines with the events and it isn't working, I want it to invoke the first event, wait for the coroutine to finish, and then move to the second!

    Also is there a way to get the individual calls from the event, so I could do something like this:

    Code (CSharp):
    1.         foreach (action myaction in myEffect)
    2.         {
    3.             Debug.Log("Effect Used...");
    4.             yield return StartCoroutine(action);
    5.         }
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    ultEvent.PersistentCalls is a list and you could potentially call Invoke on each of them individually instead of on the event itself (I've never tried it though). Linked parameters and return values definitely wouldn't work though, you'd have to significantly rework the way the LinkedValues class works if you want to use them.

    Or you could just have a list of UltEvents for the coroutine to go through instead of putting them all in one. That would also give you better flexibility since you could call multiple methods in one event if you want, without needing to change the code at all.

    I've tried using Discord for support in the past, but found that the ability to fire off a quick question and the expectation of an instant response leads people to ask questions before properly thinking through their problem or trying to read the documentation. There are also people who want to chat with me like a friend after I help them, but I simply don't have the time or inclination to deal with any of that.
     
  3. unity_8VnLFqABeZGQQQ

    unity_8VnLFqABeZGQQQ

    Joined:
    Aug 13, 2020
    Posts:
    3
    Hmm, I tried to do that:

    Code (CSharp):
    1.     public void UseEffect()
    2.     {
    3.         Debug.Log("Effect Used...");
    4.         StartCoroutine(UseEffectIEnum());
    5.     }
    6.  
    7.     public IEnumerator UseEffectIEnum()
    8.     {
    9.         foreach (UltEvent myEvent in myEventList)
    10.         {
    11.             Debug.Log("Effect Used...");
    12.             myEvent.Invoke();
    13.         }
    14.         yield return null;
    15.     }
    Code (CSharp):
    1.     public IEnumerator DestroyTempCard()
    2.     {
    3.         Debug.Log("destroying card...");
    4.         tempCard.DestroyMe();
    5.         yield return null;
    6.     }
    But it doesn't seem to call them, I don't get the "Destroying Card..." debug, even though I get the "Effect Used" debug, and I made sure that it was in the inspector effect
     
  4. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    If you're using an event to invoke DestroyTempCard, that won't work because events have no context to run coroutines in.

    You could have the event also call StartCoroutine on a MonoBehaviour and give it the Linked Return Value from DestroyTempCard. But that would start it as a completely separate coroutine, it wouldn't delay UseEffectIEnum. Getting it to work like that would require a significant rework of the whole system.
     
  5. unity_8VnLFqABeZGQQQ

    unity_8VnLFqABeZGQQQ

    Joined:
    Aug 13, 2020
    Posts:
    3
    Hmm, do you have a good idea for making a modular system that can pause and wait for input before continuing? I unfortunately haven't been able to find a good solution yet (btw this is for a trading card game, so I was using the event to quickly program card effects)

    Edit: I ditched the event system and just used a drop down menu that pulls from this.GetType().GetMethods(); It can't do params, but at least it works
     
    Last edited: Jul 12, 2022
  6. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    I've never tried anything like that but I know I wouldn't use coroutines because they have no way to show you which ones are running or where they're up to in the Unity Editor so debugging them is a pain.

    I'd probably just use the Finite State Machine system in my Animancer plugin, bit I have no idea how well suited it would actually be to this particular problem without trying it.
     
  7. DevynCole

    DevynCole

    Joined:
    Feb 23, 2018
    Posts:
    8
    I realize this is a silly question, you might get a lot of them because bonelab just recommended users use your asset in place of scripts for mods with the sdk for their game. :)

    I've got a basic button set up, where, when oncollision enter, I want to spawn an object. My issue is that the collision always registers twice, so an object always gets spawned in rapid succession. My setup is as follows.
    Oncollision ultevent on a physics object (a button the player can touch) and another object with its own delayed ultevent elswhere in my scene. When the collision is registered, the first thing it does is disable its gameobject so the collision can't happen again. The delayed event that handles spawning turns it back on after it spawns the object. I'm a little stumped, as this is a trivial thing if I could call functions on an actual script, but the mod sdk limits me from using custom scripts.
     
  8. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    It's very unlikely that the issue would be caused by UltEvents since it would be pretty obvious if it was calling things twice when invoked once.

    Try just attaching a regular script with an OnCollisionEnter method which uses Debug.Log and Debug.DrawLine to see what the collision events actually are.
     
  9. DevynCole

    DevynCole

    Joined:
    Feb 23, 2018
    Posts:
    8
    Is there a way to get the return from a get component, or find object directly from the events similar to getting transforms? This is another one of those weird bonelab things because I cant use scripts.
     
  10. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    Unfortunately, UltEvents can't call generic methods.

    It's probably possible if you call the static System.Type.GetType method with the full assembly qualified name of the component type you want, then pass that returned value into the GetComponent method which takes a System.Type (instead of the generic one you'd usually call), but that would take quite a bit of effort each time you want to set it up.
     
  11. the_awesome_gamer

    the_awesome_gamer

    Joined:
    Feb 7, 2018
    Posts:
    2
    How would I find a GameObject with a tag (eg "Player") or using the name of the GameObject (eg Player) and then adjust then set the Vector3 transforms of that object? (This is in Bonelab so I can't use scripts.) I can find the gameobject using UnityEngine.GameObject.FindGameObjectWithTag but I can't actually use the found GameObject.
     
  12. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    Unfortunately, the system would need a significant rework to be able to call methods on a returned object.

    The only way you could do it in the current system would be to write another static method which takes the GameObject and position as parameters so the first parameter can be given the found object. That means it can't be done without any scriping, utility methods like that would need to be included in the project (or in Bonelab if they're going to be relying on UltEvents for things it wasn't really designed for).
     
  13. the_awesome_gamer

    the_awesome_gamer

    Joined:
    Feb 7, 2018
    Posts:
    2
    Dang. Thanks for responding.
     
  14. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    I have situations where it still errors out; but now i was able to narrow it down to the TypeToPathToAccessor dictionary in Serialization.cs containing outdated/invalid entries.
    I attached a file that shows the issue.
    To reproduce it, attach the component to something and reorder the entries in the list or just delete the first one.
    The cached info in the dictionary will now lead to accessing the remaining/other entry as being of the type the one had it replaced.
     

    Attached Files:

  15. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    As a quick fix, just stick
    TypeToPathToAccessor.Clear();
    before the
    TypeToPathToAccessor.TryGetValue
    .

    I suspect the proper solution will be to disable type caching on any accessor with a [SerializeReference] attribute on it or any of its parents, but I'll have to look into it thoroughly when I get some time.
     
    Flavelius likes this.
  16. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    @Flavelius The attached file should fix the issue. Let me know how it goes.
     

    Attached Files:

  17. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    Thanks for the fast response, but unfortunately this doesn't yet fix it. With the example i attached above it also fails.
     
    Last edited: Mar 8, 2023
  18. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    I'm not sure how I had it working yesterday, because the PropertyAccessor constructor was completely wrong. Replace it with this:
    Code (CSharp):
    1. Parent = parent;
    2. Name = name;
    3.  
    4. if ((parent != null && parent.IsSerializeReference) ||
    5.     field == null ||
    6.     field.IsDefined(typeof(SerializeReference), false))
    7. {
    8.     IsSerializeReference = true;
    9.     return;
    10. }
    11.  
    12. Field = field;
    13. FieldElementType = fieldElementType;
     
  19. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    Yes, this seems to work correctly now. Thank you!
     
    hopeful likes this.
  20. qwertylevel3

    qwertylevel3

    Joined:
    May 8, 2018
    Posts:
    2
    Does this plugin work on Android?
    It works fine with windows platform. However when I switch platform to Android,I find all my animancer event lost
     
  21. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    UltEvents works on all platforms.

    Did you add
    ANIMANCER_ULT_EVENTS
    after switching to Android? Each platform has its own symbols.
     
    qwertylevel3 likes this.
  22. qwertylevel3

    qwertylevel3

    Joined:
    May 8, 2018
    Posts:
    2
    Thank you!!
     
  23. UDN_5c806b49-d8a0-4f67-a296-c12c91aa7396

    UDN_5c806b49-d8a0-4f67-a296-c12c91aa7396

    Joined:
    Jan 9, 2017
    Posts:
    152
    I have a persistent singleton in scene 1 with don't destroy on load. In scene 2 I have a button. How can I link the script (which is on scene 1 object) on the button event? How to set it to get instance and then run the void?
     
  24. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    Just write a regular MonoBehaviour with a public method that calls YourSingleton.Instance.Method(); then put that MonoBehaviour on the button and set the button to call the public method.
     
  25. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,364
    How do you += and -= ultEvents?
    Say you have
    public ultEvent e1, e2;
    and I want to appen e2 inside e1 with
    e1 += e2;
     
  26. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    e1 += e2.Invoke;
    should do it.
     
    laurentlavigne likes this.
  27. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,364
    Thank you!
     
  28. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,364
    And can you do math from the even interface?
    upload_2023-3-24_17-1-26.png
    For example -10 of the value read above.
     
  29. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    Not directly, but you could write some static math functions and use their return value in your actual call.
     
    laurentlavigne likes this.
  30. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,364
    Since I need properties anyway, I'll just add a Add() function to the scriptableobject.
     
  31. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,364
    Is there a way to see the list of events that were added using += ?
     
  32. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,364
    there are cases where a non-null ultEvent that show content in the inspector donothing when Invoke is called.
    any know bugs?
    any way to list on script end if the ult is actually filled with stuff?
    note: i did operations in inspector like copy paste and such and that broke the += so I'm bypassing it, seems to break in some cases.
     
    Last edited: Mar 30, 2023
  33. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    • Dynamic listeners are shown at the bottom of the event in the Inspector if there are any.
    • I'm not aware of any cases where Invoke fails to work except if you have a call that has no method assigned (or the method is missing).
    • I just tried some copying and pasting and didn't see any issues. Can you give me a specific list of steps to replicate the problem?
     
  34. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,364
    bug:
    if you pass a prefab asset as parameter to a method call
    and change that prefab at playtime
    then the method call parameter becomes null
     
  35. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    That's likely not something UltEvents can fix since it doesn't differentiate between prefabs and any other kind of reference. Do you get similar behaviour if you just reference the prefab in a regular serialized field in a script?
     
  36. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,364
    In
    public GameObject prefab
    if I swap prefab then prefab value is that new prefab. So it's a different behavior.
     
  37. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    UltEvents doesn't reference the GameObject, it directly references the Component you're calling the method on.

    Since GameObject references work, you could probably work around it by making a static method which takes the GameObject and calls GetComponent then calls whatever method you want.
     
  38. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,364
    well in this case the gameobject is the parameter, not the GO that the script is called on
     
  39. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    Can you list the steps to reproduce the bug? I can't seem to replicate the issue you're describing.
     
    laurentlavigne likes this.
  40. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    There seems to be an issue with prefab overrides. When changes that have scene references are applied from within the scene to the base prefab that prefab then somewhat expectedly contains invalid events (red, with missing references). The scene override is still valid; but in a build it prints errors (~attempt to invoke a persistent call that couldn't find its method~) as if the invalid base prefab value is used instead of the valid scene override (not happening in editor play-mode, only in builds).
     
  41. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    I'm away from home at the moment but should be able to take a look at it during the week sometime.

    Are you able to narrow the problem down any more? If you log the method name it's trying to use, is it what you'd expect? Are you sure that method actually exists in the build and isn't getting stripped out?

    Also, which version of Unity are you using?
     
  42. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    Yes, i'm somewhat sure it's exactly that issue, because when removing the invalid events from the base prefab -without changing anything else-, it doesn't error out anymore.
    Currently on 2021.3f25
     
  43. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    I wasn't able to replicate the issue in Unity 2021.3.0f1 with the LifeCycleEvents script. Could you see if it happens for you in an empty scene and if so, send me the scene and prefab to make sure I'm testing the same thing? It sounds like it might be a Unity bug since UltEvents doesn't do anything that would break basic serialization stuff like that.
     
  44. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    Thanks for looking into it.
    Unfortunately, when i tried to create a repro project, with a simple fresh one i also couldn't reproduce that behaviour.
    But while testing i found a misbehaviour that might be linked to it in some way, because the project i originally encounter the error in makes heavy use of [SerializeReference]. And when applying changed event properties with scene references to their prefab, they become invalid. this is different to the behaviour without SerializeReference where only the prefab value becomes invalid.

    (where 'Contained Events' is a [SerializeReference] field of a class containing the same events)
     
  45. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    Yeah, that's definitely a Unity bug. UltEvents has no interaction with whatever type of field you want to store it in or the prefab or variant system, that's all just Unity's serialization stuff.
     
  46. abcjjy

    abcjjy

    Joined:
    Mar 6, 2015
    Posts:
    35
    Feature request:

    A tool for migration from UnityEvent to UltEvent. Something works like [FormerlySerializedAs] that replace UnityEvent with UltEvent and preserve the callbacks.

    I use UltEvents a lot. It is an excellent plugin. However, I have an old project using UnityEvent. The migration process is a real pain.
     
  47. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    Unfortunately, the underlying data structure is too different for Unity's serialization system to support a clean way of converting between them. It's also very unlikely that I'll have any spare time to work on UltEvents any time soon with how many other projects I have to work on.
     
  48. echba11h

    echba11h

    Joined:
    Sep 25, 2022
    Posts:
    4
    There is a bug with unity 2022.3 as below.


    upload_2023-8-15_0-1-33.png
    NullReferenceException: Object reference not set to an instance of an object
    UltEvents.Editor.ObjectPickerWindow.DrawSearchBar (UnityEngine.Rect& area) (at Assets/Plugins/UltEvents/Inspector/ObjectPicker.cs:453)
    UltEvents.Editor.ObjectPickerWindow.OnGUI () (at Assets/Plugins/UltEvents/Inspector/ObjectPicker.cs:365)
     
  49. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    I just tried it in Unity 2022.3 and didn't get any errors. Did you do anything else to cause the error before opening that menu?
     
  50. echba11h

    echba11h

    Joined:
    Sep 25, 2022
    Posts:
    4
    I tried with 2D Core, 3D core, 2D UPR, 3D URP and the same error happened. The unity version I am using is 2022.3.4f1 but the same error still occurs with 2022.3.7f1
    It only happens if I want to select some system type like UnityEngine.Random.

    I didn't get this issue when using Unity 2021.3 LST.
    The attached file is a new project with only UltEvent installed. I think you can reproduce the error if you use it.
     

    Attached Files: