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. Oshigawa

    Oshigawa

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

    Angle in the prefab is set to 180, all instances are pooled before being used and properly despawned.


    Aiming is also on, i cropped it bad.

    Here's another video, you can clearly see the behaviour. They should all shoot towards player. They start shooting upwards, then they fire ok, then start shooting upwards again, i can't catch where might be the issue.

     
  2. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    Wait, i forgot to enable the define in ubhobjectpool after updating.
     
  3. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    It gets better, but as soon as the bullets start recycling i get "This bullet is already added in m_bulletList." and fly at a 180 degree angle.

    I'm sure that i'm releasing the bullets properly

    Code (CSharp):
    1. var ubhbullet = go.GetComponent<UbhBullet>();
    2.          
    3.             if (ubhbullet == null)
    4.              
    5.             {
    6.                 Debug.LogError("No UbhBullet component found in the gameObject: " + go.name);
    7.             }
    8.          
    9.             if (ubhbullet != null)
    10.              
    11.             {
    12.      
    13.             UbhObjectPool.instance.ReleaseBullet(ubhbullet, false);
    14.          
    15.             }
    The worst thing is that it's completely erratical. Bullets are ok for a while, then some of them go upwards, some of them track the target. Check this out, a complete nonsense.

     
    Last edited: May 13, 2020
  4. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @Oshigawa
    Are you activating Bullet GameObjects from anything other than UBH?
    Anyway, I won't know until I see the project, so if you send it to me, I'll check it.
     
  5. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    I tried moving from shot routine to directly calling the Shot() method from the UbhLinearLockOnShot, but it's still the same. What do you mean by activating bullet gameobjects from anything else?
     
  6. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    I made a small project, but i can't seem to reproduce it in it. However, that small project has no warnings, in the main project, when the problem occurs i get:

    c:\buildslave\unity\build\Runtime/Export.Debug.bindings.h This bullet is already added in m_bulletList coming from the ubhbulletmanager.

    I can send you the entire project if you want.
     
  7. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    A bit more of info

    Here the bullet flies ok with an angle of 76 in the inspector of linear shot for the firing object and the bullet has z rotation of 76.



    The one above it that shoots upwards by error has an angle of 79, but bullet moves way off and in the inspector of the transform Z rotation is 0 instead of 79.

     
  8. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    Ok, i'm getting closer.

    I tried an older version of project while i still didn't update to 1.5, it was probably 1.4.6 or 1.4.7 since there's no RemoveAllPool() method in UbhObjectPool and things are working fine.

    In the old version i am getting This bullet is not found in m_bulletList which is not a problem, but there's is no This bullet is already added in m_bulletList appearing with bullets flying upwards.

    So i'm guessing it might be a problem with singleton behaviour, i'll add scene loading to that small test project to see what happens.
     
    Last edited: May 13, 2020
  9. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    Everything works fine in the repro project, however, i'm using the latest CKG, i'll try updating it in the main project to see if it goes away.
     
    WestHill likes this.
  10. zimmerfreack

    zimmerfreack

    Joined:
    May 8, 2020
    Posts:
    9
    Hey,

    please help me out! I still can't figure out how to rotate the patterns. If i select AxisMove X_AND_Y and also check inherit angle the bullets will keep firing along the negative Y axis. I need them to shoot along the positive Y axis.
    If i rotate ie. the Spread8WayShot (which is a child of my player) then it does nothing! I am using the 3D Bullets Prefab in 3D environment.
     
  11. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @zimmerfreack
    The "Center Angle" property of the "Ubh Spread Nway Shot" component has a value of 180, so set it to 0.
     
  12. zimmerfreack

    zimmerfreack

    Joined:
    May 8, 2020
    Posts:
    9
    Thanks! that worked. Love the asset.

    Edit: Is there a way to make a shot truely "endless". When i put a 0.0001 delay i still get ugly holes in the patterns.
     
    Last edited: May 15, 2020
  13. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    @WestHill

    I tried new CGK, problem still remains. I tried moving Pool Boss from start scene to main scene to avoid singleton behaviour, the problem is still there. I'll write you an e-mail to avoid polluting the forums.
     
  14. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @zimmerfreack
    Which shot do you want to make endless?
    You can set AfterDelay to 0 with UbhShotCtrl, but isn't that what you want to do?
     
  15. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
  16. zimmerfreack

    zimmerfreack

    Joined:
    May 8, 2020
    Posts:
    9
    It works with the AfterDelay = 0
    For some reason i thought i cant put in 0 there because at the beginning there was like a warning saying that AfterDelay is equal to 0 and i fixed that by putting it to 0.1.

    Edit: My player now has a shot controller and an NwayShot prefab. Everything shoots fine.
    Now my question is how can i swap out the bullet prefab of the NwayShot during the game. For example:

    Code (CSharp):
    1. public bool switchPrefab=false;
    2.  
    3. if(switchPrefab==true)
    4. {
    5.    // switch prefab of nWayShot
    6. }
    I tried to access the UbhNwayshot script using the GetComponent, but it didnt work out for me. I was wondering if you have something like that already implemented ie. in the bulletManager. Next question would be if thats even recommended, or if there is a better way to achive what im trying to say.

    Sorry for all these rookie questions im new to Unity.
     
    Last edited: May 16, 2020
  17. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @zimmerfreack
    The prefab can be replaced dynamically.
    Or, if you want to implement it more easily, create two GameObjects with the UbhShotCtrl component added and dynamically switch the active state.
     
  18. zimmerfreack

    zimmerfreack

    Joined:
    May 8, 2020
    Posts:
    9
    With my knowledge i would do it like this. Accessing the component and swapping it out but whats the correct syntax to do it?

    Code (CSharp):
    1. public GameObject preFab;
    2.  
    3. gameObject.GetComponent<UbhNwayShot>().m_bulletPrefab = preFab;
     
  19. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
  20. zimmerfreack

    zimmerfreack

    Joined:
    May 8, 2020
    Posts:
    9
    It doesnt for me. I call that code from a new script tho.
     
  21. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @zimmerfreack
    This component works.

    1.Add it to the same GameObject as Shot.
    2.Press the V key while playing.

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class ShotPrefabChanger : MonoBehaviour
    4. {
    5.     [SerializeField]
    6.     private GameObject m_prefabOther;
    7.  
    8.     private UbhBaseShot m_shotComponent;
    9.     private GameObject m_prefabOrg;
    10.  
    11.     private void Awake()
    12.     {
    13.         m_shotComponent = GetComponent<UbhBaseShot>();
    14.         m_prefabOrg = m_shotComponent.m_bulletPrefab;
    15.     }
    16.  
    17.     private void Update()
    18.     {
    19.         if (Input.GetKeyDown(KeyCode.V))
    20.         {
    21.             if (m_shotComponent.m_bulletPrefab == m_prefabOrg)
    22.             {
    23.                 m_shotComponent.m_bulletPrefab = m_prefabOther;
    24.             }
    25.             else
    26.             {
    27.                 m_shotComponent.m_bulletPrefab = m_prefabOrg;
    28.             }
    29.         }
    30.     }
    31. }
     
  22. zimmerfreack

    zimmerfreack

    Joined:
    May 8, 2020
    Posts:
    9

    That works super smooth for me! You're amazing with all the support you give us!!!
     
    WestHill likes this.
  23. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    Hey @WestHill any news on this? It's easy to replicate, just use random lock on and set bullet number to 1 or 2, you will get the error and the bullet will fire and 180 angle. If you set it to three or more it works ok.
     
  24. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    Oshigawa likes this.
  25. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @Oshigawa
    Version 1.5.2 has been released to fix an error in UbhRandomShot.
    Please check it.
     
    Bagnol and Oshigawa like this.
  26. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    Great, thanks
     
  27. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    @WestHill

    Thanks man, works great.

    There's a new issue now, coregamekit has been updated so ubh is broken when using it.

    Code (CSharp):
    1. [CompilerError] The type or namespace name 'CoreGameKit' does not exist in the namespace 'DarkTonic' (are you missing an assembly reference?)
    2. Compiler Error at Assets\Plugins\UniBulletHell\Script\Singleton\UbhObjectPool.cs:11 column 17
    3. 10:   #if USING_CORE_GAME_KIT
    4. -->11:   using DarkTonic.CoreGameKit;
    5. 12:   #endif
    6.  
    Code (CSharp):
    1. [CompilerError] The type or namespace name 'PoolBoss' could not be found (are you missing a using directive or an assembly reference?)
    2. Compiler Error at Assets\Plugins\UniBulletHell\Script\Singleton\UbhObjectPool.cs:33 column 13
    3. 31:   #if USING_CORE_GAME_KIT
    4. 32:       // +++++ Replace PoolingSystem with DarkTonic's CoreGameKit. +++++
    5. -->33:       private PoolBoss m_poolBoss = null;
    6. 34:       private HashSet<Transform> m_poolPrefabTransformList = new HashSet<Transform>();
    7.  
    Code (CSharp):
    1. Assets\Plugins\UniBulletHell\Script\Singleton\UbhObjectPool.cs(147,26): error CS7036: There is no argument given that corresponds to the required formal parameter 'prefabSource' of 'PoolBoss.DestroyPoolItem(Transform, PoolBoss.PrefabSource)'
    2.  
    Also, Mini Pool Boss prefab has been introduced, i don't know if it will work with ubh.
     
  28. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @Oshigawa
    There seems to be a major change in PoolBoss initialization.
    I will be updating UBH in the coming days.
     
    Oshigawa likes this.
  29. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    Yeah, a lot of stuff have been changed due to addressables support i presume. Cheers.
     
  30. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @Oshigawa
    Version 1.5.3 has been released with support for PoolBoss initialization changes.
    Please check it.
     
    Mike891, Oshigawa and Bagnol like this.
  31. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    Great, i'll check it out and let you know if all works.
     
  32. oharinth

    oharinth

    Joined:
    Jul 8, 2015
    Posts:
    25
    There are UbhNwayShot and UbhHomingShot as shot patterns in this asset.
    But I need to make UbhNwayShot with homing missiles.
    How can I make it?
     
  33. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @oharinth
    That can be done by creating a new shot pattern script that combines Nway and Homing.
     
  34. DYV

    DYV

    Joined:
    Aug 10, 2015
    Posts:
    58
    Hi, looks like I do something wrong. My pool becomes infinite. I am not expirience, so could you tell me how to make my own bullet? Should I use some your code or can put only mine with void OnCollisionEnter(Collision other)? And what should I use instead Destroy and Instantiate?
    Thank you
     
  35. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @DYV
    The method to return the Bullet GameObject to the pool is "UbhObjectPool.instance.ReleaseBullet(UbhBullet bullet)".

    Then when firing the bullet, UBH takes it out of the pool and uses it.
     
  36. DYV

    DYV

    Joined:
    Aug 10, 2015
    Posts:
    58
    thank you for the answer, I tried it but looks like something I do wrong. Here is my code:
    Code (CSharp):
    1.  
    2. private void OnEnable()
    3.  
    4.     {
    5.         StartCoroutine(despawnAfterTime());
    6.     }
    7.  
    8.     IEnumerator despawnAfterTime()
    9.     {
    10.         yield return new WaitForSeconds(despawnTime);
    11.         UbhObjectPool.instance.ReleaseBullet(UbhBullet bullet);
    12.  
    13.     }
    And I got error
    Unexpected symbol `bullet'
     
  37. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @DYV
    The argument of the ReleaseBullet method must be passed the Bullet component attached to the bullet's GameObject.
    See the "UniBulletHell\Example\Script\UbhPlayer.cs" HitCheck method for reference.
     
  38. DYV

    DYV

    Joined:
    Aug 10, 2015
    Posts:
    58
    You use parent object but what if object references itself? Something like UbhBullet bullet = this.gameObject; but this does not work.
     
  39. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @DYV
    Use GetComponent if you want to get components that are attached to itself.
    "gameObject.GetComponent<UbhBullet>()"
    This is the information found in the Unity documentation, etc.
     
  40. DYV

    DYV

    Joined:
    Aug 10, 2015
    Posts:
    58
    thank you for patient :) but I don't understand why my pool never stop to grow. I tried to add these lines to my bullet code:
    Code (CSharp):
    1.   IEnumerator despawnAfterTime()
    2.     {
    3.         yield return new WaitForSeconds(despawnTime);
    4.  
    5.         if (bullet != null && bullet.isActive)
    6.         {
    7.             UbhObjectPool.instance.ReleaseBullet(bullet);
    8.         }
    9.    
    10.     }
    And bullet became invisible after despawnTime but it is still in the pool and this pool never stop grow. What am I missing?
     
    Last edited: Dec 11, 2020
  41. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @DYV
    If there are no bullets in the pool to be fired, a new one is created.

    The bullets returned to the pool are retained until they are reused.

    If you want to clear all the pools, you can Destroy them all by calling "UbhObjectPool.instance.RemoveAllPool()".
     
  42. DYV

    DYV

    Joined:
    Aug 10, 2015
    Posts:
    58
    My problem is that I can't return bullet to the pool. As I understand in your UBH_game_example scene bullets return to the pool by Destroy Area wich contain script with UbhObjectPool.instance.ReleaseBullet(bullet);
    Is it righ? Does code "UbhObjectPool.instance.ReleaseBullet(bullet);" return bullet to the pool?

    EDIT: nevermind, the problem is solved and now the bullets work as supposed to be :)
     
    Last edited: Dec 11, 2020
    WestHill likes this.
  43. Oshigawa

    Oshigawa

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

    I have a question, how can i modify AfterDelay of shot objects in UbhShotCtrl on runtime when i have multiple elements?
     
  44. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    Oh yeah, one more thing, can i change already fired homing bullet target on runtime somehow?
     
  45. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @Oshigawa
    All member variables of UbhShotCtrl are public.
    You can set m_shotList and m_afterDelay from script at runtime.

    As for HomingTarget, you will need to add a method to the UbhBullet class that will re-set the target.
     
    Oshigawa likes this.
  46. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    Thanks man.
     
    WestHill likes this.
  47. jangooni

    jangooni

    Joined:
    Jan 2, 2014
    Posts:
    3
    Great asset, quick question:
    @WestHill is there an easy way to convert from Vertical (default) to a horizontal 2D shooter?
     
  48. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @jangooni
    There are two ways to change the shooting angle of a bullet.

    1. Change the Angle property value of each shot (ex. "Ubh Linear Shot").

    2. Change the angle of the parent GameObject's Transform, and check the "Inherit Angle" checkbox of "Ubh Shot Ctrl".
     
    jangooni likes this.
  49. jangooni

    jangooni

    Joined:
    Jan 2, 2014
    Posts:
    3
    @WestHill Thanks! Next question, what's the recommended way to switch patterns in code at runtime? I'm manually calling StartShotRoutine() from code right now as well.

    I've already filled the shotList with 5 patters on the ShotCtrl, but want to change them at random times.
     
  50. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @jangooni
    The UbhShotCtrl member (m_shotList) is public, so you can change the shotlist dynamically.
    Or you can have multiple ShotCtrl and control them on(StartShotRoutine) / off(StopShotRoutine) from a script.