Search Unity

Uni Bullet Hell - 2D bullet hell's shot pattern system

Discussion in 'Assets and Asset Store' started by WestHill, Jun 28, 2014.

  1. DunkelBor

    DunkelBor

    Joined:
    Jan 15, 2020
    Posts:
    8
    Hi @WestHill,
    Thanks for the asset.

    I'm encountering a small problem and was wondering if you could help.
    I have a small function on an enemy where after a specific time, it uses the StartShotRoutine(0f) to shoot a pattern.
    So far, so good, however the second time the StartShotRoutine() is called the enemy shoots nothing, but on the third time it's back to shoot.
    I do have a coroutine to ensure the StopShotRoutine() function is called between two StartShotRoutine().
    Changing the time between the first and the second doesn't appear to change anything.
    I imagine I'm missing something super obvious but I can't seem to find what.
    Could you please help me there?

    Many thanks in advance. :)
     
  2. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @DunkelBor
    I'd like to check the problem.
    Could you please send me a minimal project?
     
  3. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    Hello @WestHill

    I have an issue trying to get the value of m_shotList.Item.m_afterDelay from UbhShotCtrl, i get zero and "ArgumentException: method arguments are incompatible".
     
  4. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @Oshigawa
    Make sure that m_shotList is not NULL or empty before getting the list members.

    like this
    Code (CSharp):
    1. if (m_shotList != null && m_shotList.Count >= 0)
    2. {
    3.     // do some thing...
    4. }
     
  5. DunkelBor

    DunkelBor

    Joined:
    Jan 15, 2020
    Posts:
    8
    Hi @WestHill,
    I'll prepare this and send it to you, thanks. :)
     
  6. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    Well it's not null, After Delay value is pre-set in the prefab, yet i get an error and 0 as a result. I'll get a bit deeper into it to see what is the problem.
     
  7. DunkelBor

    DunkelBor

    Joined:
    Jan 15, 2020
    Posts:
    8
    Hi again @WestHill,
    On the minimal version of the project the problem didn't appear so it is clearly somewhere on my side, I'll look into it.
    Thanks again.
     
    WestHill likes this.
  8. DunkelBor

    DunkelBor

    Joined:
    Jan 15, 2020
    Posts:
    8
    Hi again @WestHill,
    I'm having a small problem.
    With a clean import of UBH I receive one error:
    upload_2021-8-9_7-59-53.png

    The problem in the script being the following:
    upload_2021-8-9_8-0-21.png

    Any idea on how to fix it in a clean way?
    I know that commenting it out works for UBH but this creates conflict with another important package so I'd rather find a sustainable solution.

    Many thanks in advance. :)
     
  9. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @DunkelBor
    OK, I'll check it out.
    What version of Unity are you using?
     
  10. DunkelBor

    DunkelBor

    Joined:
    Jan 15, 2020
    Posts:
    8
    Hi @WestHill
    I'm using Unity 2020.3.15f2.
     
  11. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @DunkelBor
    I'm not getting that error.
    Do you have anything else installed in your project besides UBH?
     
  12. DunkelBor

    DunkelBor

    Joined:
    Jan 15, 2020
    Posts:
    8
    Hi @WestHill,

    Problem solved it came from my script Action which I simply had to rename.
    Sorry for the trouble and thanks again for the help. :)
     
    WestHill likes this.
  13. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    rrahim likes this.
  14. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @Oshigawa
    We do not plan to link it with any other assets.
     
  15. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    Hello @WestHill

    Ok, thanks.

    By the way, i'm having issues all of a sudden. Bullets started spawning in UbhObjectPool instead under Pool Boss. Pool Boss is properly initialized, #define is in enabled in UbhObjectPool.

    Clones are created under PoolBoss but they are not being activated but instead created in UbhObjectPool.

    Any ideas what to look for?
     
    Last edited: Jan 12, 2022
  16. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @Oshigawa
    Is #define the only change in UbhObjectPool?
    Or has there been an update to PoolBoss recently?
     
  17. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    @WestHill

    Yes, define is the only change. PoolBoss hasn't been updated recently as far as i know. It started happening all of a sudden.

    I'll try reimporting both assets.

    edit: reimported both, still the same.

    edit 2: wait, is this the normal behaviour:

    This one is inactive and under pool boss:



    This one is active and parented to UbhObjectPool:



    When it's released, it's reparented to Pool Boss.

    I noticed this because i have a null ref exception when the bullets are reused. When they are spawned for the first time, i get parentShot.name from UbhBullet successfully, but when the bullet is reused and i try to get it i get a null reference.
     
    Last edited: Jan 12, 2022
  18. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @Oshigawa
    Changing the parent of the bullet when using it is the intended behavior in the first release.
    If it doesn't work well with the current version of PoolBoss, it needs to be fixed.
    I'll check it later.
     
  19. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    All good, i had a race condition so i added a small delay until ubhbullet component is added to the bullet.
     
  20. chihchanglin

    chihchanglin

    Joined:
    Jul 24, 2015
    Posts:
    28
    Hi @WestHill
    In UBH_ShotShowcase, I have change LinearShot Bullet Speed from 2 to 20.
    The bullets sometimes go through player without trigger collision. (I have disabled player damage)
    Even set EnemyBulletParent Rigidbody Collision Detection to Continuous but with no luck.
    Is there anyway to fix this? :)
     
  21. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    Hi @chihchanglin
    UBH includes the pattern of the bullets, but hit detection is not a supported feature.
    The sample uses the simplest standard Unity functionality. It is only a sample.
    If you want to improve it, there are ways, such as using raycast to do hit checks with fast moving bullets.
     
  22. chihchanglin

    chihchanglin

    Joined:
    Jul 24, 2015
    Posts:
    28
    Hi @WestHill
    Where's the best place I can put my own raycast to do hit checks also movement?
    I need more detail about it. Thanks.
     
  23. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @chihchanglin
    There is no best. It depends on the project.
    Besides raycasting, for simple 2D shapes, it is sometimes faster to do the calculations yourself.
    I wish you the best of luck with your project.
     
  24. OliverL2112

    OliverL2112

    Joined:
    Feb 1, 2023
    Posts:
    2
    Hi @WestHill,

    Thanks for the asset, I've chosen to use it for my current project.

    I've done some tests and it seems that the behavior of the example patterns change when the game runs at different FPS.

    Example with spiral pattern running at ~30 FPS
    upload_2023-4-12_18-10-2.png

    And now the same pattern running at ~300FPS
    upload_2023-4-12_18-11-38.png

    I have done something wrong in the setup? Is there a way of fixing this? I need the behavior of bullet patterns to be the same across different FPS values.

    Thank you!

    Edit: Just checked and this also happens in the shot showcase example scene.
     
  25. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
  26. OliverL2112

    OliverL2112

    Joined:
    Feb 1, 2023
    Posts:
    2
    @WestHill

    I'm sending you an email since I want to show some parts of your code and I think this forum is public.
     
    WestHill likes this.
  27. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    I have been able to reproduce the problem.
    I will update the asset soon.
    Thanks! @OliverL2112
     
  28. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    Hi @WestHill

    is there a way to get the instance of a fired bullet?

    I added a property to UbhBullet i want to pass, so when the bullet is fired, i can pass the property to UbhBullet via callback, but i don't know how to access it.
     
  29. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @Oshigawa
    I will add callback events in the next update.
     
  30. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @Oshigawa
    A new version of UBH has just been released.

    The following parameters have been added to each shot classes.

    If "Use Bullet Fired Callback" is set to True (check ON) and a callback function is added to "Bullet Fired Callback Events," the function will be called with the fired bullet as an argument.

    If you do not use this function, set "Use Bullet Fired Callback" to False.

    BulletFireCallback001.png
     
    Oshigawa and rrahim like this.
  31. wkzpfm2

    wkzpfm2

    Joined:
    Jun 26, 2022
    Posts:
    4
    Hi
    My unity level is very newbie
    How can I play the pattern of the m_shotList I want?

    I want to play the pattern according to the enemyHp.

    for example
    if( enemyHp >50 && enemyHp < 100)
    {
    // pattern A
    // ubhShotCtrl.StartShotRoutine();
    }
    else
    {
    // pattern B
    }

    So, i write ubhShotCtrl.StartShotRoutine();
    But this way, all the patterns were played back and forth
     
  32. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @wkzpfm2
    There are several ways to do this.

    ex1: replace the shot list
    Code (CSharp):
    1. if (enemyHp > 50 && enemyHp < 100)
    2. {
    3.     // pattern A
    4.     ubhShotCtrl.StopShotRoutine();
    5.  
    6.     ubhShotCtrl.m_shotList.Clear();
    7.     ubhShotCtrl.m_shotList.Add(shotA);
    8.     ubhShotCtrl.m_shotList.Add(shotB);
    9.  
    10.     ubhShotCtrl.StartShotRoutine();
    11. }
    12. else
    13. {
    14.     // pattern B
    15.     ubhShotCtrl.StopShotRoutine();
    16.  
    17.     ubhShotCtrl.m_shotList.Clear();
    18.     ubhShotCtrl.m_shotList.Add(shotC);
    19.     ubhShotCtrl.m_shotList.Add(shotD);
    20.  
    21.     ubhShotCtrl.StartShotRoutine();
    22. }
    ex2: use multiple shotctrl component
    Code (CSharp):
    1. if (enemyHp > 50 && enemyHp < 100)
    2. {
    3.     // pattern A
    4.     ubhShotCtrl_B.StopShotRoutine();
    5.     ubhShotCtrl_A.StartShotRoutine();
    6. }
    7. else
    8. {
    9.     // pattern B
    10.     ubhShotCtrl_A.StopShotRoutine();
    11.     ubhShotCtrl_B.StartShotRoutine();
    12. }
     
  33. wkzpfm2

    wkzpfm2

    Joined:
    Jun 26, 2022
    Posts:
    4
    Thank you very much!!
     
    WestHill likes this.
  34. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    You're the boss. I need this to set bullet properties on runtime so i can pool less bullets and reduce overhead. Very handy callback.
     
    WestHill likes this.
  35. wkzpfm2

    wkzpfm2

    Joined:
    Jun 26, 2022
    Posts:
    4
    Hi, i added "shot controller" component and have some error
    And DemoScene have same problem

    NullReferenceException: Object reference not set to an instance of an object
    UbhShotCtrl.OnEnable ()

    The error assign here
    unibv.png
     
    Last edited: Jul 28, 2023
  36. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @wkzpfm2
    Try deleting the asset completely and re-importing it.
    If this does not improve, please send the project to me.
     
  37. wkzpfm2

    wkzpfm2

    Joined:
    Jun 26, 2022
    Posts:
    4
    I think it was a problem with the unity Editor
    I deleted uni bullet hell asset and imported it again, but it was the same, so I made a new project and moved everything I worked on, so it was solved. Thank you
     
    WestHill likes this.
  38. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    @WestHill

    Hi, can you give me a hand here, i can't seem to manage it myself, i didn't use UnityEvents much.

    I have a GameObject that holds ShotController and a type of shot (RandomShot, for example). I have a script attached that will apply modifications to fired bullet when bullet fired callback calls the method jn the attached script. Of course, i need to access the gameobject that holds the UbhBullet component. However, i just can't seem how to get the UbhBullet component from the callback.

    I see m_useBulletFiredCallback sends UbhBullet bullet parameter, so i tried something like this in my script that is called via callback:

    Code (CSharp):
    1. public void ApplyBulletSettings(UbhBullet bullet)
    2.  
    3.     {
    4.         ubhBullet = bullet.GetComponent<UbhBullet>();
    5.     }
    6.  
    Now the inspector demands from me to attach the UbhBullet parameter of course, but i can't put it by dropping it from the RandomShot.

    RandomShot inherits UbhBaseShot that defines UbhBullet, i thought that would work, but the inspector says no and i get this on runtime:

    ArgumentException: Object of type 'UnityEngine.Object' cannot be converted to type 'UbhBullet'.

    In short, BulletFiredCallback event passes the UbhBullet parameter, but i can't seem to get it from the script that is on the same gameobject as the shot preset.
     
    Last edited: Aug 25, 2023
  39. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @Oshigawa
    I have made a video on how to receive callbacks.
    See it here.

    Also, the UbhBullet passed as an argument is an UbhBullet, so it can be used as is (no need for GetComponent).
     
    Oshigawa likes this.
  40. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    Hello @WestHill

    All good, i didn't know there's two ways of using a callback, one with defined passed parameter in inspector, and one "blind".

     
  41. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @Oshigawa
    It makes sense that UnityEvents has two ways.
    StaticParameter allows you to set arguments from the Editor's Inspector.
    DynamicParameter is passed arguments at runtime.
     
    Oshigawa likes this.
  42. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    Makes sense, learned something new. Thanks again.
     
    WestHill likes this.
  43. LastSipahi

    LastSipahi

    Joined:
    Sep 14, 2011
    Posts:
    21
    Hi, I've searched the thread but can't found it, is anybody tried to implement a basic player path prediction to this asset ? I'm not good at vector math. A simple not targeting the player but target the players next position related to players speed, direction and distance to bullet caster should be enough.

    Problem is this asset's bullet casting system uses only angles. Sorry, if this is simple vector math calculation but currently I'm lost.
     
  44. zartan917

    zartan917

    Joined:
    Feb 13, 2017
    Posts:
    6
    hi im new to posting on unity. unihell is great im able to have it shoot almost instantly. But how to have when a bullet hits my biker player it restarts level? does anyone know? thanks
     
  45. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @zartan917
    It's not about UBH Asset, it's the basics of Unity, the minimum code required is to reload the scene on hit events.

    If you want to try this with the UBH sample scenes, rewrite the contents of the Damage method of the UbhPlayer class to this.
    Code (CSharp):
    1. SceneManager.LoadScene(SceneManager.GetActiveScene());
     
  46. zartan917

    zartan917

    Joined:
    Feb 13, 2017
    Posts:
    6
    thank you