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
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Energy Bar Toolkit - 2D and 3D Progress Bars

Discussion in 'Assets and Asset Store' started by genail, Mar 30, 2013.

  1. genail

    genail

    Joined:
    Jul 2, 2012
    Posts:
    1,042
    Hello Guin,
    Hmm, that looks quite strange. Did Set Bar Value had "Every Frame" option before? Does it work now as expected or isn't working at all?

    I cannot look into it right now because I'm on vacations, but most probably at the beginning of next week I will be able to get my hands on it. I'm sorry, I cannot think of any workaround at the moment :-(

    Piotr

    P.S. Why Set Bar Value seems to be disabled on your screenshot?
     
  2. GuinUK

    GuinUK

    Joined:
    Feb 27, 2017
    Posts:
    44
    Hi Genail,

    Hope you are enjoying the holiday!

    I'm not sure - I updated my screenshot to show you the full working - according to the Playmaker forum the bool 'update every frame' used to be there but I can't see it. Also not sure why it greys out?

    Don't worry too much until you get back - if you can see an instant mistake I have made let me know.

    Thanks in advance,
    Guin
     
  3. GuinUK

    GuinUK

    Joined:
    Feb 27, 2017
    Posts:
    44
  4. genail

    genail

    Joined:
    Jul 2, 2012
    Posts:
    1,042
    Thanks!

    Yeah, it should be there. You can also try to remove and install playmaker integration once more time, maybe you overwritten the bundled version with older version somehow? Please use only the PlayMaker Integration package from inside Energy Bar Toolkit directory.

    If it won't help, I will get back to you as soon as I will know something more!
     
    GuinUK likes this.
  5. GuinUK

    GuinUK

    Joined:
    Feb 27, 2017
    Posts:
    44
    There we go!

    Yes I had installed the package within the package, and then installed it off the website which overwrote it.
    The one in the scene addon worked a treat

    healthFixed.png

    Have a good vacation!

    Guin
     
  6. genail

    genail

    Joined:
    Jul 2, 2012
    Posts:
    1,042
    Hi!
    I've just tested EBT on newest 2017.1. It seems you have a script called "Mask" somewhere in your project and it conflicts with Mask type of UnityUI. Please rename your Mask script and everything should be working just fine.

    P.S. I see that I need to update texture import settings. If you see any graphical errors, please switch your texture Mesh Type to "Full Rect".

    Piotr
     
  7. genail

    genail

    Joined:
    Jul 2, 2012
    Posts:
    1,042
    Try importing EBT package into an empty project - you won't see that error.
    Mask class is built-in Unity type (https://docs.unity3d.com/ScriptReference/UI.Mask.html), I cannot change its name. I always recommend to put game classes in namespaces (like MyAwesomeGame.Mask). Keeping things in top namespace often causes issues like this one.
     
  8. nuonical

    nuonical

    Joined:
    Feb 28, 2015
    Posts:
    46
    What is the proper way to drain energy via script?

    I'm using something like (pseudo-code) :

    Code (CSharp):
    1. // Drain Energy
    2. if(Input.GetKeyDown(KeyCode.Space) && energyBar.ValueF > 0) {
    3.   energyBar.ValueF -=  0.65f * Time.deltaTime;
    4. }
    5.  
    6. // Recharge Energy
    7. else if(energyBar.ValueF < 1.0f) {
    8.   energyBar.ValueF +=  0.5f * Time.deltaTime;
    9. }
    With the assumption that we are draining energy at 50% per second (0.5f * Time.deltaTime), since ValueF is a value between 0 and 1.0f (0-100%).

    This works as expected in the editor at around 60fps. However, in a build this runs closer to 120fps, and the energy bar typically drains too fast, and barely recharges on it's own. This is being run in the Update() loop, so Time.deltaTime should be normalizing the values.

    Is this a floating point issue or is there something I'm missing?

    Thanks!
     
  9. genail

    genail

    Joined:
    Jul 2, 2012
    Posts:
    1,042
    Hi,
    I'm very sorry, I missed the notification about this message :-(
    Everything seems to be ok. Most probably the bug is somewhere else. Do you modify bar value in other places?

    -
    Piotr
     
  10. twelveplusplus

    twelveplusplus

    Joined:
    Mar 25, 2013
    Posts:
    12
    I'm having a bit of a problem. I am using energybar toolkit with "2D+3D infinite runner toolkit" unfortunately, when i enable my energy bar in the canvas, nothing else can be scene on screen in my android builds... like, the rest of the screen is completely black :(

    any ideas?
     
  11. genail

    genail

    Joined:
    Jul 2, 2012
    Posts:
    1,042
    Hi!
    Could you please post a screenshot of that issue and a screenshot of Inspector panel showing Energy Bar object and its renderer?
     
  12. twelveplusplus

    twelveplusplus

    Joined:
    Mar 25, 2013
    Posts:
    12
    ok, here is what i have, and what it is supposed to look like (what it looks like from the unity editor game screen).

    This is drivin me nuts...
     

    Attached Files:

  13. nuonical

    nuonical

    Joined:
    Feb 28, 2015
    Posts:
    46
    This turned out to be a floating point precision error. Increasing the max energy value from 100 to 1000 fixes the issue. Thanks for the reply!
     
    hopeful likes this.
  14. twelveplusplus

    twelveplusplus

    Joined:
    Mar 25, 2013
    Posts:
    12
    ^^

    i was actually also having the same type of problem earlier. I was using a 0-100 energy bar, and i couldn't seem to get it to register if I used values lower than

    energyBar.ValueF -= 0.01f;

    like, if the setting was 0.01f or higher the bar would drain. any lower and the value would remain without changing. I decided to just give up on using floating point values and I just decremented the value by 1 each update. seems to work fine for my purposes.
     
  15. nuonical

    nuonical

    Joined:
    Feb 28, 2015
    Posts:
    46
    Yep, 0-100 here as well. There is probably a cast to (int) that's messing with things internally.

    What I did was keep track of the energy value separately and then just assign ValueF to show the status. You definitely want to multiply your energy drain by Time.deltaTime in order to normalize the rate. Right now someone running at 100fps will drain energy twice as fast as someone running at 50fps, which is probably unintended.

    So something like this for draining / recharging (pseudo-code) :

    Code (CSharp):
    1. public float DrainEnergy; // Are we draining energy?
    2.  
    3. float drainRate = 100; // Drain x energy units per second (100 units == 100 / 1000 or 10% a second)
    4. float rechargeRate = 50; //Recharge a little slower than we drain
    5. float currentEnergy = 0;
    6. float maxEnergy = 1000; // Use 1000 instead of 100
    7.  
    8. Update() {
    9.  
    10.   // Drain
    11.   if(DrainEnergy && currentEnergy > 0) {
    12.     currentEnergy -= drainRate * Time.deltaTime;
    13.   }
    14.   // Recharge if not draining
    15.   else if(!DrainEnergy && currentEnergy < MaxEnergy) {
    16.     currentEnergy += rechargeRate * Time.deltaTime;
    17.   }
    18.  
    19.   // Update the visual display of the energy bar
    20.   energyBar.ValueF = CurrentEnergy / MaxEnergy;
    21. }
    22.  
     
  16. genail

    genail

    Joined:
    Jul 2, 2012
    Posts:
    1,042
    That's wired...
    Try making a new canvas with the bar to be the only object on it. If it does not help, will you be able to reproduce that issue on a blank scene and send it back to me?
     
  17. twelveplusplus

    twelveplusplus

    Joined:
    Mar 25, 2013
    Posts:
    12
    oh, ok, yes that was gonna be the next thing I tried. So, i made a new canvas, and i used it on the same camera, and no cigar, but i made a new CAMERA and put the new canvas on it, and that did the trick!

    Also, the same problem was showing up when i tried to make a web player build.

    I have no idea what could have been causing it, but having a separate camera and canvas solved the problem.
     
  18. genail

    genail

    Joined:
    Jul 2, 2012
    Posts:
    1,042
    Hmm, I have to try that... It sounds bad...
    I'm glad that you've solved that out! :)
     
  19. christougher

    christougher

    Joined:
    Mar 6, 2015
    Posts:
    500
    Upgraded my project to unity 2017.1 and got this problem with the repeated bars' filled sprite when I clicked on them.

    "Texture must be set as readable. Set it now?"

    When I clicked yes I had to reset the texture as a UI element again.

    This was going unnoticed until I finally clicked on one but I *think* is preventing entire panels from showing up in the builds... worked fine in the editor but is baffling the hell out of me why my UI isn't showing up in builds. Any problem with repeated bars in unity 2017?
     
  20. genail

    genail

    Joined:
    Jul 2, 2012
    Posts:
    1,042
    Hi!
    Unfortunately there are some issues with new Unity version. I'm working on the new EBT version as we speak. I'm sorry for the issue, I will send the release as soon as possible.
     
  21. christougher

    christougher

    Joined:
    Mar 6, 2015
    Posts:
    500
    It's nice to have an answer! I was going crazy lol. I knew better then to update when there was no benefit or reason to. If you have a ballpark estimate of release that'd be great, if not I'll wait patiently. I got plenty to work on.
     
  22. zukinet

    zukinet

    Joined:
    Oct 30, 2016
    Posts:
    51
    Hi,

    i just purchased Energy Bar Toolkit...

    now i want to create circle energy bar...
    but i dont have NGUI except Doozy UI...

    How i can create it ?

    thanks in advance...
     
    Last edited: Sep 3, 2017
  23. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    444
    Is Mad Level Manager still supported? I'm getting a lot of errors in Unity 2017.1. Sorry for posting here, but it seems that the proper forum is not active at this time.
     
  24. zukinet

    zukinet

    Joined:
    Oct 30, 2016
    Posts:
    51
    Hi,

    i got below error after upgrade to v4.0.0 :



    any idea ?
     
  25. genail

    genail

    Joined:
    Jul 2, 2012
    Posts:
    1,042
    @zukinet I'm sorry, I didn't receive a notification for some reason.
    Currently Unity UI bars are the only one supported. Is Doozy UI working on Unity UI (Canvas)?

    About the upgrade. Please remove your current Energy Bar Directory and import it again. New Unity version has a lot of new changes, so I needed to remove the deprecated code. Sorry about that! Please let me know if that worked!

    @username132323232 Sorry, notifications issues :/ I'm sorry to tell but Mad Level Manager is no longer supported. Are these errors or just warnings? Please contact me on support@madpixelmachine.com, I will send you the newest version I have.
     
  26. Moukib

    Moukib

    Joined:
    Nov 7, 2012
    Posts:
    7
    Hello, I really like your asset, great work. I had to update to the last Unity beta (2017.2.0b11) and even from a new project I get this error:

    Probably it's a new issue from the beta changes, thanks in advance :)
     
  27. genail

    genail

    Joined:
    Jul 2, 2012
    Posts:
    1,042
    Thanks!
    The new fixed version has just been released! :) Have fun!

    Piotr
     
  28. christougher

    christougher

    Joined:
    Mar 6, 2015
    Posts:
    500
    Hi, been using EBT a LOT lately :). Here are a few wishes to add. First, I'm using several EBT toolbars in my menu which has Timescale set to 0 to pause the game. It would be really nice if we could have a setting to ignore time scale for the effects such as the smooth effect.

    Also, I'm using some EBTs to as health indicators that follow the 3d objects using the UGUI. The first frame that the energy bar toolkit is instantiated and/or reactivated (due to enemies spawning/respawning) has the bar show up very briefly right in the middle of the screen. I'm not sure how to best stop this from happening.

    I'd also like it if I could disable or alter the alpha of the image(s) as needed. Thx!
    Chirs
     
  29. TanselAltinel

    TanselAltinel

    Joined:
    Jan 7, 2015
    Posts:
    152
    Hi!

    Firstly, this is a great asset and I've been using it for a long time. So, thanks for all your work!

    Well, I'm having a bit of a problem here now. I've upgraded to 4.0.1 (clean import) and Unity 2017.2 and one of my bars are not working as they should. I.e. value is 200 (min 0, max 300), but bar is showing full, and when value is 100 it shows just one bar gone (i.e. 1/3)

    Interestingly, any other bars are working fine. Any ideas?
     
  30. genail

    genail

    Joined:
    Jul 2, 2012
    Posts:
    1,042
    Hi!

    Could you please send me your bar prefab along with the textures to support@madpixelmachine.com? Please use unitypackage format.

    Thanks!
     
  31. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,028
    Hi, I'm getting these errors with the latest version of Unity:
     
  32. genail

    genail

    Joined:
    Jul 2, 2012
    Posts:
    1,042
    Hi!
    I will send you something as a PM to try it out. If it will work, I will release the patch.
     
  33. paolo-suarez

    paolo-suarez

    Joined:
    Jul 21, 2015
    Posts:
    2
    Having trouble with the energy bar , enabling disabling the root canvas a few times when loaded.
     
  34. genail

    genail

    Joined:
    Jul 2, 2012
    Posts:
    1,042
    I believe we moved this conversation to e-mail already :) I will post the solution here if any or just release a fixed version.
     
  35. recreativestudios

    recreativestudios

    Joined:
    Aug 5, 2015
    Posts:
    1
    I am also having this issue on the newest version of Unity and the newly released version of your package.
     
  36. genail

    genail

    Joined:
    Jul 2, 2012
    Posts:
    1,042
    Hi! Did you receive the package as a PM? Please let me know if it fixes your issue.
     
  37. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    297
    Hello @genail

    I love your asset and i have a question. It's a bit specific, and maybe i didn't fiddle around enough. I need a repeated bar that would be gradient, so, for a simple example, if i have a bar that repeats 3 times and a green to red gradient, i would get one green, one orange, and one red bar. I hope you understand what i mean :)
     
  38. genail

    genail

    Joined:
    Jul 2, 2012
    Posts:
    1,042
    Hello Kruko,
    Sorry, I've been on vacations.

    Do you have a reference maybe?
     
  39. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    297
    Hello @genail

    Sure, something like these



     
  40. genail

    genail

    Joined:
    Jul 2, 2012
    Posts:
    1,042
    @Kruko You should be able to do this using Filled Renderer :)

    Look into the examples. There are bars with stripes using Filled Renderer. Then you can change the color to "gradient" and you can get very similar effect to the one above.

    Please let me know if you need my help with this!
     
    hopeful likes this.
  41. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    297
    Hello @genail

    yeah i already have a bar that works that way, but the whole bar changes colors when i increase/decrease bar value.
     
  42. genail

    genail

    Joined:
    Jul 2, 2012
    Posts:
    1,042
    Yes, you're correct. Seems like even I forget from time to time how some functions are working :)



    I'm thinking of making a shader that may allow that.
    As a workaround I would suggest to prepare a texture so it will contain a gradient like you'd like to see:

    bar2_bar.png
     
    Oshigawa likes this.
  43. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    297
    Great idea, thanks!
     
    genail likes this.
  44. Lork

    Lork

    Joined:
    Jul 12, 2013
    Posts:
    72
    I've been playing with various settings trying to deal with the issue of energy bars moving in coarse looking steps in the case of values that change slowly over time, but I haven't had much luck.

    In this gif you can see that the smooth effect works well for the quickly changing green bar, but the slowly regenerating grey bar doesn't look so hot:



    I was able to alleviate it a bit by setting the max value to 1000 instead of 100 so it moves in smaller steps, but that only seems to go so far (no improvement going from 1000 to 10000 from what I could tell). Do you have any advice on how to handle this case, or could you perhaps make any updates to improve on it?
     
  45. genail

    genail

    Joined:
    Jul 2, 2012
    Posts:
    1,042
    Hello @Lork ,
    I'm sorry, I've missed the notification e-mail somehow...

    I think you should try and play with Canvas rendering settings. It looks like it's set to pixel-perfect manner. Try disabling Pixel Perfect option on your Canvas and let me know if that helps. If not, I should be in front off my PC by tomorrow and I can try experimenting with that too :)

    Cheers!
    Piotr
     
  46. Lork

    Lork

    Joined:
    Jul 12, 2013
    Posts:
    72
    I checked and it's not set to pixel perfect. Anyway, I'm fairly certain this is not a rendering issue but rather a natural consequence of the way the bars work. I've made a better example gif:



    The bottom number is the actual value I'm feeding into the bar with SetValueF(), which is slowly decreasing at a constant rate. The top number is the current value set by the bar itself which only changes every so often because it's an integer, at which point the bar jumps by 1/100th of its width. This is what I mean by 'coarse steps'.

    The smooth effect works well in cases where eg. the value abruptly changes from 100 to 50, or for constant changes over a certain speed, but is impractical (from what I can tell) for slowly changing values like the one in my gif. Because the time between 'steps' is so long it's very difficult to find a smooth effect speed that would make the bar appear to change smoothly, and of course even if you were to find such a value it would interfere with cases where the value changes abruptly or quickly.

    Edit:

    While testing I also noticed another edge case issue:



    If you've changed the scale of a bar, the burn effect doesn't inherit that. Additionally, the burn is drawn as an entire bar underneath the base one rather than as one that starts where the base ends. This doesn't matter when you have an opaque bar, but it looks a little weird with a translucent one as you can see.
     
    Last edited: Dec 18, 2017
  47. genail

    genail

    Joined:
    Jul 2, 2012
    Posts:
    1,042
    I checked and it's not set to pixel perfect. Anyway, I'm fairly certain this is not a rendering issue but rather a natural consequence of the way the bars work. I've made a better example gif:



    The bottom number is the actual value I'm feeding into the bar with SetValueF(), which is slowly decreasing at a constant rate. The top number is the current value set by the bar itself which only changes every so often because it's an integer, at which point the bar jumps by 1/100th of its width. This is what I mean by 'coarse steps'.

    The smooth effect works well in cases where eg. the value abruptly changes from 100 to 50, or for constant changes over a certain speed, but is impractical (from what I can tell) for slowly changing values like the one in my gif. Because the time between 'steps' is so long it's very difficult to find a smooth effect speed that would make the bar appear to change smoothly, and of course even if you were to find such a value it would interfere with cases where the value changes abruptly or quickly.

    [/QUOTE]

    But now I'm not sure if I understand what you're trying to achieve. Do you want the bar to grow smoothly with subpixel precission? If yes, then it may be done by using ortho camera and by switching Canvas to world space. You just need to align it with the canvas. EBT bars are using UI/Default build-in shader and it seems to not allowinw subpixel values for edges when it's set to screen space.


    Ouch... Sorry for that. I will send you the updated unitypackage :)

    Piotr
     
  48. Gruguir

    Gruguir

    Joined:
    Nov 30, 2010
    Posts:
    322
    hello @genail , i hit the 'PropertySpecialResizeMode' issue (UT 2017.2.1f1) could you help ?
     
  49. genail

    genail

    Joined:
    Jul 2, 2012
    Posts:
    1,042
    Hi,
    I'm sorry for this issue. I will release the new version shortly. In the meantime I will send you the link to it as a PM :)
     
  50. Gruguir

    Gruguir

    Joined:
    Nov 30, 2010
    Posts:
    322
    hey thanks but it gives me another error (UT 2017.2.1F1) :
    Assets/Energy Bar Toolkit/Scripts/uGUI/Editor/EBTPackerPolicy.cs(16,14): error CS0535: `EnergyBarToolkit.EBTPackerPolicy' does not implement interface member `UnityEditor.Sprites.IPackerPolicy.AllowSequentialPacking.get'
     
unityunity