So the latest on this situation.
In the process of setting up my UI, I’ve run into some issues, and I have yet to even fully test the actual mixing part, though that is the piece I’m currently working on setting up, the code in the UI that lets me do just that.
Attached is an image of what I have so far in the UI. It successfully pulls all the necessary information for the concepts a character has into the scroll area on the left without issue (right now it just displays them all, rather than it being dependent on equipment in some way, a problem I’ll want to address after I have the core system working).
The goal is to be able to click the icon for the concept on the left, then click a slot in the window on the right and place it there. When the concept gets placed, it should perform the mix check, then if that results in an ability, the abilities name and stats should show up in the relevant textboxes.
Right now I’ve got a coroutine that starts when you click the button for the icon in the concepts list that walks thought the steps one at a time, waiting for input from the player.
But right now I’m getting really weird Null Reference Exceptions that are sorta baffling me. The first one happens when I run the method I use to update the ability screen. I know up to a certain point the code is working perfectly, since the mini character pod and concepts window are working perfectly fine. It’s when I get to drawing the ability slots that the first one goes
//Draw Ability Window
for (int j = 0; j < toDraw.abilitySlots.Length; j++) {
if (toDraw.abilitySlots [j].slot != null) {
//Draw Created Ability Parameters
AbilitySlotNames [j].text = toDraw.abilitySlots[j].slot.name;
AbilitySlotPowers [j].text = "Power: " + toDraw.abilitySlots[j].slot.GetPower();
AbilitySlotForces [j].text = "Force: " + toDraw.abilitySlots[j].slot.GetForce();
AbilitySlotPreps [j].text = "Prep Time: " + toDraw.abilitySlots[j].slot.GetPrepTime() + "s";
AbilitySlotCasts [j].text = "Cast Time: " + toDraw.abilitySlots[j].slot.GetCastTime() + "s";
AbilitySlotCooldowns [j].text = "Cooldown: " + toDraw.abilitySlots[j].slot.GetCooldown() + "s";
AbilitySlotStamina [j].value = 1f - (toDraw.abilitySlots[j].slot.GetStaminaCost() / 100);
AbilitySlotDamageType [j].gameObject.SetActive (true);
AbilitySlotTargeting [j].gameObject.SetActive (true);
} else {
//default state
AbilitySlotNames [j].text = "Empty";
AbilitySlotPowers [j].text = "Power: 0";
AbilitySlotForces [j].text = "Force: 0";
AbilitySlotPreps [j].text = "Prep Time: 0s";
AbilitySlotCasts [j].text = "Cast Time: 0s";
AbilitySlotCooldowns [j].text = "Cooldown: 0s";
AbilitySlotStamina [j].value = 1f;
AbilitySlotDamageType [j].gameObject.SetActive (false);
AbilitySlotTargeting [j].gameObject.SetActive (false);
}
for (int k = 0; k < 4; k++) {
//Draw Concept Slot Contents
Vector2 iterator = new Vector2((float)j, (float)k);
if (GetConceptSlotButton(iterator) != null) {
GetConceptSlotButton(iterator).image.enabled = true;
GetConceptSlotButton(iterator).image.sprite = toDraw.abilitySlots [j].GetConcept(k).Icon;
} else {
GetConceptSlotButton(iterator).image.enabled = false;
GetConceptSlotButton(iterator).image.sprite = null;
}
}
}
This line in particular…
if (toDraw.abilitySlots [j].slot != null) {
Is the line that it says is throwing the error.
The other issue is happening in my previously mentioned coroutine, when I try to click the button hidden in the ability slot, where the actual adding to the ability slot is supposed to happen.
public IEnumerator ConceptPlacingAndMixing()
{
Character toDraw = MCP.instance.GetCharacterFromParty(primaryCharacterSelection);
for (int i = 0; i < mainMenuButtons.Length; i++) {
//loop though buttons to hide concept buttons
ConceptIcons [i].interactable = false;
}
subMode = 1;
while (subMode != 0) {
//At this point, the concept to be placed has already been selected, it's just a matter of placing it,
//then attempting to mix the contents of the slots, to see if an ability results.
Debug.Log("Starting Concept Placement Process");
if (subMode == 1) {
//a nested loop to activate all of the concept slot buttons
for (int j = 0; j < 6; j++) {
for (int k = 0; k < 5; k++) {
Vector2 iterator = new Vector2((float)j, (float)k);
GetConceptSlotButton(iterator).interactable = true;
GetConceptSlotButton(iterator).image.enabled = true;
}
}
Debug.Log ("Successfully Set all concept buttons to be interactive");
ChangeInformation ("Select a Concept slot to place the selected concept in");
conceptLocation = -Vector2.one;
while (conceptLocation == -Vector2.one && subMode == 1) {
yield return null;
}
if (conceptLocation != -Vector2.one) {
subMode = 2;
}
Debug.Log ("Successfully Selected a concept location");
continue;
}
if (subMode == 2) {
//set the concept into the slot, then perform a Mix check, to see if an ability
//should also be added.
Debug.Log ("Now Placing concept, Attempting to place in slot #" + (int)conceptLocation.x);
toDraw.abilitySlots[(int)conceptLocation.x].AddConcept(toDraw.GetConceptToDraw(secondaryCharacterSelection));
GetConceptSlotButton(conceptLocation).image.sprite = toDraw.GetConceptToDraw (secondaryCharacterSelection).Icon;
toDraw.MixAttempt ((int)conceptLocation.x);
UpdateSingleAbilitySlot ((int)conceptLocation.x);
subMode = 0;
}
}
//Return all buttons to normal.
for (int i = 0; i < mainMenuButtons.Length; i++) {
//loop though buttons to hide concept buttons
ConceptIcons [i].interactable = true;
}
for (int j = 0; j < 5; j++) {
for (int k = 0; k < 4; k++) {
Vector2 iterator = new Vector2((float)j, (float)k);
GetConceptSlotButton(iterator).interactable = false;
}
}
yield return null;
}
In this instance, the line…
toDraw.abilitySlots[(int)conceptLocation.x].AddConcept(toDraw.GetConceptToDraw(secondaryCharacterSelection));
…is the one throwing the error, the line literally adding the concept to the slot.
In both cases, I’m not sure what even could be having a problem, I’m pretty sure everything exists, because it’s all visible in the inspector, and you can see my debug.logs where I tested the ability slot and it always wrote something out that I was expecting to see. The common denominator seems to be the actual ability slot on the ability slot class, but I have no idea why this would be a problem.