Starting game with things on action bar

I’m wondering if there’s a way we can get the player to start off the bat with the abilities already on their action bar without saving.

I’m trying to move away from the “abilities are items” kind of way, and whenever I have a fresh load I need to buy the abilities and they go into my inventory.

I just kind of want the abilities already on the bar when players start up the game. Is there a way for us to do this, and if so, where do I start to look at for it??

First, you’ll need an array of abilities to add to the store…
Then get hold of the store, and one by one add each ability on the list to it’s corresponding slot in the store.
You want to do this in Awake() because if you do it in Start(), you’ll get really ugly race conditions with the Saving System.
I’ve blurred my solution, so you can have a go at it.

Try it first, no peeking!
using GameDevTV.Inventories;
using UnityEngine;

[RequireComponent(typeof(ActionStore))]
public class AbilityLoader : MonoBehaviour
{
    [SerializeField] private ActionItem[] itemsToPreload;
    
    private ActionStore actionStore;
    
    private void Awake()
    {
        actionStore = GetComponent<ActionStore>();
        for(int i=0;i<itemsToPreload.Length;i++)
        {
            actionStore.AddAction(itemsToPreload[i], i, 1);
        }
    }
}

So i think I can figure that out without peeking (which I haven’t, I promise)… but… am I doing this INSIDE the action store script, or am I doing this in abilities, or on another script altogether?

My version uses a new script, which is a component you add to the Player (or if you’re into programming AI to use spells not that hard, really, to your enemies as well. And forget about using those silly IDs… you can make an array of ActionItem

I had just debugged why my XP bar showed leveling up at 50% for about 2 hours prior to trying this (I had literally had the equation right at the start but went “oh no, there’s no way that works” without testing it), so I gave up after staring at a foreach loop trying to think it through for 20 minutes before unblurring your solution.

The only issue I found is that it doesn’t, for some reason, load up the icons for the abilities.

How would you go about implementing this to the AI for enemies? have their mana regen after a bit and have them use an ability when they have the mana for it? I’m really interested in writing enemy AI, but I have no idea where to start haha

That’s a bigger topic. At some point, I’ll write a tutorial on it. I can give you the rough notes…
First, you need a tag for Offense, or Defense. Then you need a Condition, the times when this would be a valid choice. For example: You might have Heal with a Condition of HealthUnder(50%), or an Attack where Player’s Health is under 50%.

You’ll then have a Preservation Instinct score for the AI between 1 and 100… Health Percentage determines whether the npc prefers Offense or Defense. We then put each filtered skill that the AI has enough mana for into a pool… if preference is Offense, then the offensive skills get 2 entries in the pool. If the preference is defense, then the defensive skills get 2 entries in the pool. Finally we draw a skill from the pool and cast it.

Targeting can require some special attention, for example DelayedClickTargeting doesn’t work for AI, but Delayed Click Targeting could simply return the player when the AI is casting.

I eagerly await your tutorial on it.

A side note, the fix to pre load the abilities doesn’t load up the abilities icons, is this just an issue with preloading? It works fine when you drag it on, but when it’s preloaded NO icons show up. Everything shows up after you slot another action item into the action bar.

Is update icon getting called before we slot the preloaded abilities, and then not afterwards?

It shouldn’t be, but one never knows…

This is a case I would go with brute force in ActionStore()

void Start()
{
     storeUpdated?.Invoke();
}

Privacy & Terms