Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

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:
    318
    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:
    318
    Wait, i forgot to enable the define in ubhobjectpool after updating.
     
  3. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    318
    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:
    148
    @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:
    318
    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:
    318
    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:
    318
    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:
    318
    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:
    318
    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:
    6
    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:
    148
    @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:
    6
    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:
    318
    @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:
    148
    @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:
    148
  16. zimmerfreack

    zimmerfreack

    Joined:
    May 8, 2020
    Posts:
    6
    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:
    148
    @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:
    6
    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:
    148
  20. zimmerfreack

    zimmerfreack

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

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    148
    @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:
    6

    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:
    318
    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:
    148
    Oshigawa likes this.
  25. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    148
    @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:
    318
    Great, thanks
     
  27. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    318
    @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:
    148
    @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:
    318
    Yeah, a lot of stuff have been changed due to addressables support i presume. Cheers.
     
  30. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    148
    @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:
    318
    Great, i'll check it out and let you know if all works.
     
unityunity