because my game does not access my Scriptable Object
I apologize beforehand if there are things misspelled because I am Spanish-speaking and everything here is translated by Google ...
I have a very strange problem ...
When I compile my project for Android and run it on any phone, regardless of the version of Android I have, the game acts differently than it does in the Unity Editor, but in addition to that after Build and only after finishing a Build; when running it in the editor it starts to act exactly the same in the editor as it does on the phone
The weirdest thing is the following ... I have in my project a Scriptable Object that acts as a "Database" and from which I retrieve important information, everything that has to do with the Ships in my game, each one of the statistics, is rescued from that "Base Data "in all scenes
Attached the Script:
[CreateAssetMenu(menuName = "Ship System / Database")]
public class Database : ScriptableObject
{
public List<Ships> shipsList;
public Ships FindShipInDatabase(int id)
{
foreach (Ships ship in shipsList)
{
if(ship.id == id)
{
return ship;
}
}
return null;
}
public Ships FindShipInUse()
{
foreach (Ships ship in shipsList)
{
if (ship.inUse == true)
{
return ship;
}
}
return null;
}
}
[System.Serializable]
public class Ships
{
[Header("SHIP INFORMATION")]
public int id;
public string name;
public float cost;
public bool acquired;
public bool inUse;
[Header("STATS")]
public Stats stats;
[Header("SKILL INFORMATION")]
public bool skillReady;
public float lvlSkill;
public float skillCoolDown;
public float skillTime;
[TextArea(5,5)] public string skillDescription;
[System.Serializable]
public struct Stats
{
public float speed;
public float strength;
}
}
Said Scriptable Object is created as an Asset to be able to access it from any scene ... it turns out that after the Build when the project begins to behave in the same way as on the phone, if I click (Literally) or access that Asset that represents my Database and is shown in the inspector then at that precise moment it stops behaving the same way it does on mobile and begins to behave as it should always
The real problem is that ...
I have a menu where you can buy the ships and I have two buttons, one that is to buy it and another to use it. I will attach the script with the two functions below:
public void Comprar()
{
//Se resta el precio de la nave al monto total de monedas y se almacena en una clave
int resta = dataCollector.monedasTotales - (int)ships.cost;
totalRestante = resta;
PlayerPrefs.SetInt("CoinRecord", totalRestante);
//Se guarda el valor booleano adquirido en la base de datos
ships.acquired = true;
//Si la nave fue adquirida se desactiva el boton y se guarda en una clave del texto del boton
if(ships.acquired == true)
{
buttonList[0].GetComponent<Button>().interactable = false;
string textButton;
textButton = "Nave Adquirida";
textList[0].text = textButton;
PlayerPrefs.SetString("TextButtonCompra", textButton);
//Se evalua si la nave esta en uso o no y se toman acciones dependiendo de ello
if (ships.inUse != true)
{
buttonList[1].GetComponent<Button>().interactable = true;
textList[1].text = "Usar";
}
else
{
buttonList[1].GetComponent<Button>().interactable = false;
textList[1].text = "Nave en uso";
}
}
}
public void Usar()
{
database.FindShipInUse();
if(database.FindShipInUse() != null)
{
//Se usa una variable interna para almacenar el indice de la nave que se encuentra en uso
int shipUseId;
shipUseId = database.FindShipInUse().id;
//Se utiliza dicha variable para desactivar el uso de la nave que ya no se usara
database.FindShipInDatabase(shipUseId).inUse = false;
shipList[shipUseId - 1].SetActive(false);
//Se coloca el valor de la nave actual en USO
database.FindShipInDatabase(index).inUse = true;
//Se cambia el texto del boton al colocar la nave en uso
buttonList[1].GetComponent<Button>().interactable = false;
textList[1].text = "Nave en uso";
int idShip;
idShip = index - 1;
Debug.Log(idShip);
// Se guarda el indice de la nave en uso
PlayerPrefs.SetInt("IndexShipInUse", idShip);
}
}
As you can see, if the ship is not purchased it cannot be used and when you buy it and "Use it" it is marked in the Database that that ship (which I access by its unique id) is in use and that information is rescued within of the game itself to know the LvlSkill or skill level and thus be able to carry out different actions depending on it, but by following the steps mentioned above with respect to build, and pressing the "Use" button, the boolean is not modified in the "Database" ... It is only modified if I access the Asset of the Database from the unity inspector as mentioned above and because of this in the game what should happen does not happen, since that value is not changing when it should.
In the apk that I run on Android it must be happening exactly the same ... for some reason it does not access the database when buying and using the ship, so the information that the game collects is wrong.
Does anyone know what may be happening? ... And thanks in advance for any response.
Your answer
Follow this Question
Related Questions
After compiling and installing apk game becomes transparent and you can see the mobile home screen 1 Answer
Failed to re-package resources 0 Answers
Can't Build with IL2CPP for Android after 2018.3.0 Update(Empty Project) 1 Answer
Android Build Error because of no certificate?? 0 Answers
Can't build apk getting error 0 Answers