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 Nishioka @WestHill , i'm having a slight problem, i was hoping you could help me out. When i set the ubhshotctrl to start on awake and loop, it fires by spawning bullets from pool boss, so that's fine.

    Here's the setup of the weapon:



    Here's the setup of the state machine since i'm using Playmaker. Nothing special, used it before.


    I enabled both states to be visible but only one is used actually. When i use Invoke Method, it used to work fine, now i get only one bullet spawned which doesn't move and i get this message

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. UbhBaseShot.ShotBullet (.UbhBullet bullet, Single speed, Single angle, Boolean homing, UnityEngine.Transform homingTarget, Single homingAngleSpeed, Boolean wave, Single waveSpeed, Single waveRangeSize) (at Assets/UniBulletHell/Script/ShotPattern/UbhBaseShot.cs:148)
    3. UbhRandomShot+<ShotCoroutine>c__Iterator0.MoveNext () (at Assets/UniBulletHell/Script/ShotPattern/UbhRandomShot.cs:89)
    4. UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
    5. UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    6. UbhRandomShot:Shot() (at Assets/UniBulletHell/Script/ShotPattern/UbhRandomShot.cs:39)
    7. UbhBaseShotInspector:DrawProperties() (at Assets/UniBulletHell/Script/Editor/UbhBaseShotInspector.cs:25)
    8. UbhBaseShotInspector:OnInspectorGUI() (at Assets/UniBulletHell/Script/Editor/UbhBaseShotInspector.cs:10)
    9. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
    10.  
    When i use Start Coroutine it works ok, but i always get 'already shooting' warning

    Code (CSharp):
    1. Already shooting.
    2. UnityEngine.Debug:LogWarning(Object)
    3. <ShotCoroutine>c__Iterator1:MoveNext() (at Assets/UniBulletHell/Script/Controller/UbhShotCtrl.cs:125)
    4. UnityEngine.MonoBehaviour:StartCoroutine(String)
    5. HutongGames.PlayMaker.Actions.StartCoroutine:DoStartCoroutine() (at Assets/PlayMaker/Actions/StartCoroutine.cs:78)
    6. HutongGames.PlayMaker.Actions.StartCoroutine:OnEnter() (at Assets/PlayMaker/Actions/StartCoroutine.cs:54)
    7. HutongGames.PlayMaker.FsmState:ActivateActions(Int32) (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:199)
    8. HutongGames.PlayMaker.FsmState:OnEnter() (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:169)
    9. HutongGames.PlayMaker.Fsm:EnterState(FsmState) (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2670)
    10. HutongGames.PlayMaker.Fsm:SwitchState(FsmState) (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2628)
    11. HutongGames.PlayMaker.Fsm:UpdateStateChanges() (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2556)
    12. HutongGames.PlayMaker.Fsm:UpdateState(FsmState) (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2686)
    13. HutongGames.PlayMaker.Fsm:Update() (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:1920)
    14. PlayMakerFSM:Update() (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/PlayMakerFSM.cs:532)
    15.  
    I can comment out the debug message and keep firing away happily, but i don't why invoking the method doesn't work? I also tried calling the shot() method directly but i get the same error.

    I fail to see why i get the exception error since the object reference IS using owner.

    Edit: Now it also happens that the coroutine is started, but no bullets are being spawned.
     
    Last edited: Nov 9, 2017
  2. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    I've got the same setup on some enemies, and invoking the shot method on shot pattern script works flawlessly. I'm using the latest UBH version, Unity 2017.2. Weapon holding the ubh scripts is spawned on runtime and childed, but everything looks fine in the inspector.
     
    Last edited: Nov 9, 2017
  3. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    Hi @Kruko ,

    In UBH, Shot() method of each Shot component (ex. UbhRandomShot) should not be called directly.
    Be sure to start a shot from the StartShotRoutine() method of UbhShotCtrl.

    I do not have PlayMaker, so it may be misplaced.
    In that case please send me the smallest project by email.
     
  4. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    It works in a blank project. In the current one, i get this when i invoke startshotroutine method of ubhshot ctrl

    Code (CSharp):
    1. Assertion failed: Assertion failed on expression: 'CompareApproximately(SqrMagnitude(result), 1.0F)'
    2. UnityEngine.Quaternion:Euler(Single, Single, Single)
    3. UbhTransformExtention:SetEulerAnglesZ(Transform, Single) (at Assets/UniBulletHell/Script/Utility/UbhTransformExtention.cs:170)
    4. UbhBullet:Shot(UbhBaseShot, Single, Single, Single, Single, Boolean, Transform, Single, Boolean, Single, Single, Boolean, Single, Single, Boolean, Single, AXIS, Boolean) (at Assets/UniBulletHell/Script/Bullet/UbhBullet.cs:132)
    5. UbhBaseShot:ShotBullet(UbhBullet, Single, Single, Boolean, Transform, Single, Boolean, Single, Single) (at Assets/UniBulletHell/Script/ShotPattern/UbhBaseShot.cs:148)
    6. <ShotCoroutine>c__Iterator0:MoveNext() (at Assets/UniBulletHell/Script/ShotPattern/UbhRandomShot.cs:89)
    7. UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    8. UbhRandomShot:Shot() (at Assets/UniBulletHell/Script/ShotPattern/UbhRandomShot.cs:39)
    9. <ShotCoroutine>c__Iterator1:MoveNext() (at Assets/UniBulletHell/Script/Controller/UbhShotCtrl.cs:144)
    10. UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    11. UbhShotCtrl:StartShotRoutine() (at Assets/UniBulletHell/Script/Controller/UbhShotCtrl.cs:82)
    12.  
    Edit 1: When i comment out the define for poolboss, it works, but it display the compareapproximately error again.

    Edit 2: I didn't set up the camera frustum correctly, and i have the command to despawn the bullet when it's not visible in frustum. I disabled that, and now the bullets spawn from poolboss, i still get the compareapproximately error with every bullet and i'm unable to set the random angle. I put it on 270 degrees in prefab, but when it spawns it IS set to 270 degrees, but shoots under 90 degree angle and doesn't react to changes in inspector.
     
    Last edited: Nov 10, 2017
  5. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    Ah, rigidbody2d on the bullets was set to kinematic/simulated, that's the source of the problem!

    All's well now, sorry for the hussle!
     
  6. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    Oh but wait, something's not good yet.
     
  7. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    Here it is, the assertion failure on expression compareapproximately appears when i set the bullet number in ubhrandomshot on 3 or less. I'll try increasing the wait time between method calls to see if anything changes.
     
    Last edited: Nov 10, 2017
  8. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    No, wait time between two method calls doesn't matter, error still appears. There's definitely a problem with ubh random shot pattern, linear shot works fine.

    I'll try replicating it in a smaller project.
     
    Last edited: Nov 10, 2017
  9. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
  10. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    Sure, as soon as i set it up.
     
  11. MrJBRPG

    MrJBRPG

    Joined:
    Nov 22, 2015
    Posts:
    40
    I wonder what is the latest update with 1.35? it would be great to add specific changes done so you can better remember the changes you made. The tool itself is very promising.
     
  12. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    In UBH 1.3.5, the UI of GameExampleScene is changed to UGUI.
    Because old GUI system was warninged in Unity 2017.x.
     
    agito1987 and Oshigawa like this.
  13. agito1987

    agito1987

    Joined:
    Mar 13, 2013
    Posts:
    27
    Hey, quick question.
    Everything works great, thank you for the Core Gamekit update.
    I now start implementing enemys that only shoot when in range. I activate and deactivate the components that hold the unibullet scripts. The first time they are activated it works. once they are disabled and re-enabled it won't shoot.
    Can you tell me why this happens or how I can work around this?
     
  14. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    Hi
    Please call the "UbhShotCtrl.StopShotRoutine" method before you disable UbhShotCtrl.
    And please call the "UbhShotCtrl.StartShotRoutine" when resuming.
     
    agito1987 likes this.
  15. agito1987

    agito1987

    Joined:
    Mar 13, 2013
    Posts:
    27
    Hey, just a feature request for the future.

    When using core game kit it manages the spawning and despawning of the game objects.
    (So the same issue I had with the disabling of the shooting script. it won't fire again ones it is respawned after it was already used once.)

    So unibullet would work much better in tandem with core game kit if the shooting script would still work when disabled and re-enabled. (Even without the core game kit I think this would be a nice feature to have.)

    Keep up the great work. It is really a great asset!
     
  16. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    Hello Nishioka,

    any ideas how can i set the parent of the bullet to the origin object? It is parented to object pool by default (or poolboos if i'm using it instead), there's no way i can tell which object actually fired it and i need it.

    Edit: Ah, i got it, i just get the name property from the shot object of ubh shot ctrl.
     
    Last edited: Dec 20, 2017
  17. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    Hi
    UbhBullet component has a parentShot property.
     
    Oshigawa likes this.
  18. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
  19. Oshigawa

    Oshigawa

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

    i'm having trouble again :(

    I touched nothing, and all of a sudden i get "This bullet is already added in m_bulletList." and the behaviour on the gif. I tried updating to the latest version, but nothing.

    https://i.imgur.com/CsBZEN3.gif

    As you can see, when i fire a bullet when the old one is despawned, everything is ok, when i fire plenty od them, it gets messed up. I use startshot routine to fire, when i let go of the key i call stopshot routine.

    Any advice?
     
    Last edited: Feb 20, 2018
  20. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    Hi

    I want to fix it.
    Could you send me your project?
     
  21. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    I will send you the link to PM. Also i will make the scenario for the assertion failer on randomshot.
     
  22. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
  23. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I just purchased this to add more punch and polish to my sci-fi shmup. I'm pleased to say that it's working fine so far on the Wii U platform and looks really good. I also have Core GameKit so I'm looking forward to getting it all integrated today. Thanks for a great asset.
     
  24. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    It took a little figuring out, but I converted my bullet system over to Ubh and all is working very well.
     
  25. aandnot

    aandnot

    Joined:
    Oct 26, 2017
    Posts:
    6
    I'm having a lot of trouble getting this setup correctly. I followed your tutorial but all I end up with is shots moving in a single direction; generally in the positive Y axis. Any help would be appreciated. I'm happy to send you my project.
     
  26. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I had this same problem and it turned out to be something to do with needing some object pool thing in the scene. If you look at the example scenes you'll see one in there and you can just copy to your own scene.
     
  27. aandnot

    aandnot

    Joined:
    Oct 26, 2017
    Posts:
    6
    Thanks. I tried adding it but it still didn't work. I might try using the example scene as a skeleton for my game.
     
  28. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    sorry.
    I neglected to update the tutorial scene.
    I will update it to work.
    thx.
     
  29. aandnot

    aandnot

    Joined:
    Oct 26, 2017
    Posts:
    6
    Great, thanks!
     
  30. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @Kruko @aandnot
    UBH ver1.3.7 has been released in which your reported problems have been fixed.
    thx.
     
  31. aandnot

    aandnot

    Joined:
    Oct 26, 2017
    Posts:
    6
    Great, it works now! Thanks so much!
     
  32. MrJBRPG

    MrJBRPG

    Joined:
    Nov 22, 2015
    Posts:
    40
    Is there any way to make sure that Start Shot Routine is only called once? I am having behavior issues form running another coroutine that that calls the shot routine. I will also send you a separate message to describe the behavior bug and give out a small test file.
     
  33. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
  34. hedgeh0g

    hedgeh0g

    Joined:
    Jul 18, 2014
    Posts:
    102
    Hello, thanks for this awesome mod!

    I have a problem/feature request. I've got a couple of linear decel shots (basically I have a negative number on Acceleration Speed). These shots at some point will inevitably go backwards, which is not what I want.

    I want a shot that starts with a normal speed decaying to a slower speed BUT the speed must not go below zero or any other positive number. Can you suggest me any work around? Or, perhaps, implement this feature?

    Thanks in advance.
     
  35. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @hedgeh0g
    Thank you for your request.
    I will add a minimum & maximum speed option.
     
  36. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @hedgeh0g
    UBH ver1.3.8 has been released, which includes properties of max speed & min speed of bullet.
    thx.
     
    hedgeh0g likes this.
  37. hedgeh0g

    hedgeh0g

    Joined:
    Jul 18, 2014
    Posts:
    102
    Thanks for the support!

    I just came up with another critical suggestion. Your UBH Shot Ctrl uses a Start on Awake + a Delay. Which is ok, but not optimal.

    The same way you are using an Object Pooler to pool bullets, someone (like me) uses an object pooler to pool enemies. This, inevitably causes a problem with Start on Awake.

    Say, we have Enemy[1], Enemy[2]... Enemy[n] each of them with a different Shot Ctrl for a large variety of shot patterns.

    Our Enemy Generator Script is set up to spawn (enable) enemies in this order:

    Enemy[1] -> OnAwake, Shot Ctrl is executed.
    Enemy[2] -> OnAwake, Shot Ctrl is executed.
    Enemy[3] -> OnAwake, Shot Ctrl is executed. Enemy[1] becomes disabled, back in the pool.
    Enemy[1] -> OnAwake, Shot Ctrl can't be executed as this is the same instance of Enemy[1] we have seen before.Thus, OnAwake has already been executed.

    My suggestion is to consider replacing Start on Awake with Start on Enable and Start on Awake Delay with Start on Enable Delay.
    The workaround is to not use an object pooler for enemies which, again, is not optimal. Particularly when you have a scene where enemies are supposed to spawn and despawn very fast.

    I didn't went through all your code, but I'm confident to say that replacing OnAwake with OnEnable wouldn't cause issues. But if it is so, I'm open to your suggestions.

    Thanks again for your efforts.
     
  38. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @hedgeh0g
    I will add that option in the future ver.
    thx.
     
  39. MrJBRPG

    MrJBRPG

    Joined:
    Nov 22, 2015
    Posts:
    40
    I an curious if there is any way to actually access the most recently (latest) enabled / instantiated object from the ubh shot control because I want to pass down some parameters form one object to another, such as a bomb object spawning a bomb blast, which the bomb has a UbhShotCtrl component. If not, then I will have to find my own way around.
     
  40. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    UbhShotCtrl does not have that feature.
    I will look for a better way to get it.
     
  41. IcenEdel

    IcenEdel

    Joined:
    Jun 18, 2017
    Posts:
    4
    What are the terms of use for this asset? Available to use for free or commercial use?
     
  42. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
  43. MrJBRPG

    MrJBRPG

    Joined:
    Nov 22, 2015
    Posts:
    40
    Thanks... The problem becomes most apparent when wanting to deactivate the object that contains the ubhShotCtrl after shooting because when deactivating a game object that has a coroutine running, it stops the coroutine.

    This question would come in handy should you get deeper into coroutines, invokeRepeating, and its effect from deactivating / destroying objects:
    https://answers.unity.com/questions/34169/does-deactivating-a-gameobject-automatically-stop.html


    Edit 1:

    I realized that the problem is that the ubh shot control only looks for the object by prefab name and then finds the first-most inactive object with a ubhbullet component. There is currently no option for a "deep copy / overwrite" on a reactivated object when the prefab attached may have different values from various components beyond ubh bullet.

    I do wish there was a way for a "deep copy / overwrite" on existing prefabs that have more than searching or deep copy only when there are no inactive matching bullet names.

    I will send you screenshots through email directly shall you wish for more detail.
     
    Last edited: May 10, 2018
  44. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @MrJBRPG
    This problem can be solved in another way.
    You can reach from UbhBullet to UbhShotCtrl in this way.

    You should check the "parentShot" property of UbhBullet.
    The "parentShot" property is the UbhBaseShot component.
    The UbhBaseShot class has a property of "shotCtrl".
    The "shotCtrl" property is the UbhShotCtrl component.
    If the shotCtrl's GameObject is inactive, release the bullets or do whatever you want.
     
  45. kurasu1415

    kurasu1415

    Joined:
    Jan 27, 2015
    Posts:
    6
    @WestHill I'm attempting to use CircleShot. Is there a way to not make the sprite of the bullets rotate? I am using pixel art and therefore rotating the sprite looks bad. I simply want the bullets to spawn in a circle and move outward, not actually rotate the bullet sprite.
     
  46. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @kurasu1415
    There is no way to not rotate bullets at present,
    I think that it can be solved by making the sprite a child of the bullet and turning it opposite the angle of the bullet.
     
  47. MrJBRPG

    MrJBRPG

    Joined:
    Nov 22, 2015
    Posts:
    40

    So far, it worked with mixed results, and I can easily access the shot itself since it has the bullet prefab inside to access and change parameters directly by creating a public function to get the parent shot.

    However, I am not yet able to get it to work every time, which is what I want to get done.

    I will send you an email in more detail since it is going to be very specific.
     
  48. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @MrJBRPG
    ok I will check the email.
     
  49. Yawarshah

    Yawarshah

    Joined:
    Nov 2, 2015
    Posts:
    13
    Can I use this asset with unity 2017.1.3 ?? I dont want to upgrade to 2017.4 .. I require a bullet asset but upgrading is not an option at the moment..

    Please advise !! Thanks
     
  50. WestHill

    WestHill

    Joined:
    Oct 29, 2012
    Posts:
    174
    @Yawarshah
    Hi

    UBH works even at 2017.1.3.
    To do that, you only need to open it in 2017.1.3 after downloading UBH with the latest version of Unity.

    thx.