Search Unity

Selectionator: weighted selections with magicfind

Discussion in 'Assets and Asset Store' started by beeftime, Jun 13, 2015.

?

Would you be interested in a price-reduced .dll version of this asset?

Poll closed Sep 13, 2015.
  1. Yes

    0 vote(s)
    0.0%
  2. No

    2 vote(s)
    100.0%
  1. beeftime

    beeftime

    Joined:
    May 14, 2014
    Posts:
    43
    Hello everyone,
    My first asset, Selectionator, has been released.

    Selectionator is a weighted selection engine for Unity that has been designed to incorporate with existing projects as seamlessly as possible. It's fast, resilient to errors, and extremely easy to use. It's most powerful feature - and one that is unique to any available asset - is the inclusion of a selection sweetening algorithm, used in many games as gold- or magic-find.



    The Selectionator support website has use details and examples. But, in short, you just have to tag classes with the interface ISelectable, which will let you set a selection weight. Then, you can use the Selector class to run selections over any collection of ISelectable objects.

    Check out the demo, and note how fast it can make thousands of selections, even over large sets. This makes it viable for use in procedural level generation or AI decision-making.

    Please leave any feedback or questions you have here, and I'll address them as soon as possible.

    Thanks!
    Beeftime
     
    Last edited: Sep 13, 2015
  2. beeftime

    beeftime

    Joined:
    May 14, 2014
    Posts:
    43
    Added a poll to try to gauge interest in a .dll version (the source wouldn't be available to edit). Users wouldn't be able to change or add selection pivots or sweetener adjustment variations, but the price would be reduced.
     
  3. beeftime

    beeftime

    Joined:
    May 14, 2014
    Posts:
    43
    Selectionator v2 has been released featuring some significant changes:
    • The ISelectable interface has been tweaked so that users can store, or generate, a selection weight through any property, field, or method that returns a float value. SIelectables will also inherit a new field, due to:
    • Tweaks resulting in much better generation times, especially when dealing with bonuses over very large selection sets .
    • In certain cases, Selectionator could make serialization more difficult. No so anymore.
    • Some users reported Selectionator throwing line ending warnings in the editor. This should not be the case anymore, for anyone. Of course, please tell me if that's happening for you after the update.
     
    Last edited: Sep 16, 2015
  4. beeftime

    beeftime

    Joined:
    May 14, 2014
    Posts:
    43
  5. beeftime

    beeftime

    Joined:
    May 14, 2014
    Posts:
    43
  6. beeftime

    beeftime

    Joined:
    May 14, 2014
    Posts:
    43
    I had a question about the implementation of version 2, so I'll elaborate.

    Classes implementing ISelectable must implement a method named GetSelectionWeight() that takes no parameters and returns a float. This method must have a body, but can be anything that fulfills the requirements of the interface (takes no parameters and returns a float).
    This means (the big change from version 1) that automatically implementing the interface doesn't enable selection sets. You'll still need to provide a return value for the GetSelectionWeight() method, like so:

    Code (CSharp):
    1. public class MyClass : ISelectable
    2. {
    3.         public float GetSelectionWeight()
    4.         {
    5.             return _selectionWeight;
    6.         }
    7.     private float _selectionWeight;
    8.     public float AdjustedSelectionWeight { get; set; } //This does not need to be set
    9. }
    You don't need to do anything for AdjustedSelectionWeight (besides include the field in the class). It's part of version 2's optimizations. It's a handle for Selectionator that dramatically improves selection times over large and very large selection sets.

    This means a little more hassle when implementing Selectionator, but the upshot is that Selectionator will work without issues regardless of serialization scheme (and is faster, to boot)

    Thanks!
    p.s. The documentation has been changed, for clarity's sake
     
    Last edited: Dec 31, 2015
  7. nixter

    nixter

    Joined:
    Mar 17, 2012
    Posts:
    320
    Nice asset!

    It seems like it would be very useful for any game where drop rates change dynamically during the game. Most games have static drop rates, not requiring this level of complexity but I can imagine some interesting uses for this.

    You suggest that this may have value for AI decision-making. Can you elaborate how that might work? This system is purely random so I'm not sure how it would make game agents behave more logically in a believable fashion.
     
  8. beeftime

    beeftime

    Joined:
    May 14, 2014
    Posts:
    43
    Thanks!
    Weighted selections aren't exactly purely random. In fact, the reason weights are used are to control just how random a choice is. Selection weighting is actually a pretty core component of many AI and machine learning approaches. I'll give a really quick Unity-flavored example:

    An enemy mob in our RPG might have a few behaviors it could engage in, let's say "Attack", "Heal" and "Escape". We want to generally pursue a best course of action, something like "Attack until you're low on health, then heal - or run if you're really outclassed".
    If we try to code this as a behavior tree it's either really predictable (it'll attack until 20% HP, then it will heal, then etc.), or really time consuming to write and frustrating to test ( if health < 20% and rng.val > 50% then X else Y etc etc...)

    Weighted selections, on the other hand, allow for as much randomness as we'd like, but still preserve the general ideas we're going for, and give us interesting or complex behavior for a minimum of development time. Instead of determining exactly what we want the mob to do and when, we can model behavior based on "wants":

    If we're at full health, we just want to attack the player, so let's start with that:
    Behavior : Weight
    ATTACK : 100
    HEAL : 0
    ESCAPE : 0

    But we want to heal at low health, so maybe something like:
    ATTACK : 100
    HEAL : HP_MAX - HP_CURRENT
    ESCAPE : 0
    This way, the chance we'll heal gets higher as our HP decreases.

    But, if we're close to death, we need to get out:
    ATTACK : 100
    HEAL : HP_MAX - HP_CURRENT
    ESCAPE : if (HP_CURRENT < 20) HEAL_WEIGHT * 2

    (keep in mind these values are pulled from thin air, for the sake of example)

    Every tick/frame/whatever the monster would re-weight his options, and when it's appropriate to make a decision, Selectionator would return an action based on weight.

    So if he's low on health, our monster starts to really want to bail - but still has a chance to take a parting shot or drop a heal, which would change his mind about running, if he got enough health back.

    We can keep adding on like this to generate really complex behavior. Maybe the monster has a defense ability that negates a round of damage - we can have him watch the player's SPECIAL_ENERGY value, and now it's like he's anticipating the player using a special attack. We could also reference the player's current HP when considering escape and weight it high if the player is at high health when we're at low health, but keep it low or neutral if our monster has the HP advantage.

    As a game developer this is a really nice approach because it is easier (in many cases) to write, but way, way easier to test and adjust than most AI solutions. Decision trees and hardcoded behavior require lots of trial and error (or really intense debug modes and editors).
    Weights, on the other hand, can just be exposed during development, and even at runtime. Bind a key to increase enemy aggression or defensiveness or passivity and you can tweak in game mode.

    I hope that gave you a few ideas. If you have any other questions, please let me know!
     
    Last edited: Dec 31, 2015
    tcmeric likes this.
  9. beeftime

    beeftime

    Joined:
    May 14, 2014
    Posts:
    43
    I should also take this opportunity to say that Selectionator v3 is coming soon, and will include better visualization options and tweaks. I can't give a solid date, but hopefully shortly after the new year.
     
    Last edited: Dec 31, 2015
  10. nixter

    nixter

    Joined:
    Mar 17, 2012
    Posts:
    320
    Thank you for that detailed reply.

    I do see the value in using this with AI. There are some needs and decision-based AI systems: DecisionFlex and NEEDSIM Life Simulation which I believe both use some randomization in their decision making. I would say though that some caution and range adjustment is necessary, particularly if the determination is made often (every second or every tick).

    For instance in your example, HEAL : HP_MAX - HP_CURRENT means that the enemy AI would have a 10% chance of healing itself at 10% health loss, correct? If the update check is every second, then in ten seconds the enemy would almost certainly expend resources to heal itself despite the fact that it was hardly wounded at all. Even if we set a limit of if (HP_CURRENT < 50), in two seconds it would always heal itself.

    Perhaps a better system would be to determine each time the enemy is hit. HP_MAX - HP_CURRENT = 10% chance to heal itself after a weak minor hit, HP_MAX - HP_CURRENT = 50% chance to heal itself after a strong hit. So the percentage is still dynamic and variable, but the AI makes the decision once and sticks with it until a new hit changes the situation.


    UPDATE: See below.

    I can see how randomness could help with a large group of AI characters, such as in an RTS or SIMcity type game, or anything that is simulating a world of moving agents. For instance, in a traffic system like GTA a small number of cars might break down and pull to the side of the road waiting for repairs. The chances of this happening might depend on the age/condition of the vehicle. Or if there are monsters attacking a fantasy village, a higher percentage of townspeople stay and fight if the PC was willing to teach them how to fight earlier in the game.

    Glad to hear you are still working on this. I am confused though. It says on the Asset Store that v2 is already released. Am I reading that wrong?
     
    Last edited: Dec 30, 2015
  11. nixter

    nixter

    Joined:
    Mar 17, 2012
    Posts:
    320
    Actually I mischaracterized the AI system you were describing. It is weighing the best option, not selecting a rare and unlikely event each check. This would work with the examples you give and could be tweeked for believable behavior.

    Sorry for misinterpreting that.
     
  12. beeftime

    beeftime

    Joined:
    May 14, 2014
    Posts:
    43
    Good catch, meant 3 but wrote 2. Version 3 is what I'll be getting ready shortly.

    And yeah, the example is something I pulled out of the air. Obviously you'd have to find appropriate times to weight and make decisions for your particular project. I just wanted to show how weighted selections can be used to quickly create complex-looking behavior.
    And yeah, you're on the money: the weighting is dynamic, but decisions are made at specific times (whatever those might be for the game - turns probably). Sorry if that caused some confusion.
     
  13. StaticGame

    StaticGame

    Joined:
    Feb 12, 2017
    Posts:
    5
    Hi,I bought the Selectionator - Weighted Selection Engine yesterday, but I found the bonus function not working. (Tested in Unity5.1 and 5.6)
    Please fix it thanks.
     
  14. beeftime

    beeftime

    Joined:
    May 14, 2014
    Posts:
    43
    A new version is out -- it greatly simplifies ISelectable (now you only need to implement SelectionWeight, a float) and fixes the bug where bonus values were not being applied correctly.

    Also, the price has been reduced to $7!
     
  15. Duffer123

    Duffer123

    Joined:
    May 24, 2015
    Posts:
    1,215
    @beeftime ,

    Can i use this Asset for my loot system maybe with dictionaries for prefixes, suffixes, rarities, materials etc.

    I read your original posts on Diabolic and wondered how much this asset would help and how best to store the item attributes background data... in scriptableobjects, prefabs?
     
  16. Imillionaire

    Imillionaire

    Joined:
    Dec 14, 2012
    Posts:
    60
    hello this product looks amazing and seems to have great visuals, the issue though is that i would like to use these formulas in my games backend cloud service, so players cannot cheat, is this possible with the codes provided when i purchase the asset? or is everything hidden in DLL's?
     
  17. thusky

    thusky

    Joined:
    Nov 28, 2017
    Posts:
    6
    I sent an email to your website address, hope it reaches you but also messaging here in case you missed it, interested to chat more about your old asset "Diabolic", see you soon! :)
     
    Duffer123 likes this.