- Home /
Inspector value resets on prefabs
In my game I have a prefab with a Chest Room class attached, which inherits from a Room class.
In my GameManager class i have a List, in which in inspector I assigned my room prefabs
The problem is, that when I try to read rooms danger value in my code, it resets to 0 (Any only that, assigned Transforms and prefab Tiles remains unchanged) as you can see in screenshot below. And obviously I don't change that value in my code in any way.
After instantiating the prefab, the danger value it's still 0. I can change that by doing it in Start() on Awake() function but obviously I want to check it before instantiating it. Do you know why is it working like that or what I can do to solve my problems? Here is the code of randRoom function:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
public List<Room> rooms = new List<Room>();
public int corridorDanger;
public Room randRoom(int curr)
{
List<Room> temp = new List<Room>(rooms);
for (int r = 0; r<temp.Count; r++)
{
Debug.Log(rooms[r].danger);
Debug.Log(temp[r].danger);
}
Room room = null;
for (int i = 0; i < temp.Count; i++)
{
Room tempS = temp[i];
int randomIndex = Random.Range(i, temp.Count);
temp[i] = temp[randomIndex];
temp[randomIndex] = tempS;
}
for (int t = 0; t< temp.Count; t++)
{
if(temp[t].danger + currDanger > 0 || temp[t].danger + currDanger < 0)
{
//TODO
}
else
{
room = temp[t];
}
}
return room;
}
}
,
Answer by SillyFilly · Oct 04, 2019 at 07:29 PM
I've solved it. Quite stupid mistake.
For anyone having the same problem - values in edit mode (two clicks on prefab) are overwritten by the basic ones (one click).