Hi, im using easy save for the first time and im in love,
I have a proceduraly game like the binding of isaac, for go to other room i create it some points that have the reference of the next room,
my problem come when i load all the scene, some references to the other room works good and others have a null reference.
I dont know how to solve this, im autosaving the scene with events in none and saving with ES3.AUTOSAVEMSG.SAVE()
How i handle the save : There is a gameobject that have all the rooms as a child and i just save that gameobject with Save children enabled.
Thanks for your time, and sorry for bother i tried xD
https://imgur.com/a/JpMsKnx
https://imgur.com/usEzJJS
My script lose reference of another object when load
Re: My script lose reference of another object when load
Hi there, and thanks for getting in contact.
The reference you’re trying to save: is it generated at runtime, or does the object exist in your scene prior to entering play mode? Are you getting any warnings in the console?
Please could you also post the script itself so I can try to replicate it at my end.
All the best,
Joel
The reference you’re trying to save: is it generated at runtime, or does the object exist in your scene prior to entering play mode? Are you getting any warnings in the console?
Please could you also post the script itself so I can try to replicate it at my end.
All the best,
Joel
Re: My script lose reference of another object when load
Hi, thanks for reply so fast :3
It is generated in runtime, i have rooms prefabs with doors like "north south east west" with this script , it have a collider in each one , when the collider detect some other door my script get the reference of the next point and destroys the collider.
My rooms are generated like choose a direction nort south east or west and just apply +30 or -30 in the direction.
All works good in the first cycle all the reference doors works good , then i save my gameobject Parent that have all rooms as a child and i put my script to ES3types so they are saved.
When i load as i say previously some "nextDoors" are null , no errors. no nothing.
You can see in the scripts that some rooms are disabled, but this dosnt affect , some disabled rooms have "nextDoor" good and some others null.
My doors are created like that https://imgur.com/a/zEhUqOp
Big collider is for check next door and small collider inside Door child, just for collide with the player, the reference spawn is just a gameobject that you can ignore it ,is just for check when i need to go to teleport(it have no real doors xD) . Hope it helps
Thanks for helping.
It is generated in runtime, i have rooms prefabs with doors like "north south east west" with this script , it have a collider in each one , when the collider detect some other door my script get the reference of the next point and destroys the collider.
My rooms are generated like choose a direction nort south east or west and just apply +30 or -30 in the direction.
All works good in the first cycle all the reference doors works good , then i save my gameobject Parent that have all rooms as a child and i put my script to ES3types so they are saved.
When i load as i say previously some "nextDoors" are null , no errors. no nothing.
You can see in the scripts that some rooms are disabled, but this dosnt affect , some disabled rooms have "nextDoor" good and some others null.
My doors are created like that https://imgur.com/a/zEhUqOp
Big collider is for check next door and small collider inside Door child, just for collide with the player, the reference spawn is just a gameobject that you can ignore it ,is just for check when i need to go to teleport(it have no real doors xD) . Hope it helps
Thanks for helping.
Code: Select all
public class NewDoorTeleport : MonoBehaviour
{
public GameObject doorSpawn;
public Transform cameraPosition;
public GameObject nextDoor;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (nextDoor != null)
{
Destroy(this.GetComponent<BoxCollider>());
}
}
private void OnTriggerStay(Collider other)
{
if (other.CompareTag("Exits"))
{
other.GetComponent<NewDoorTeleport>().nextDoor = doorSpawn;
nextDoor = other.GetComponent<NewDoorTeleport>().doorSpawn;
Destroy(transform.gameObject.GetComponent<BoxCollider>());
//
}
if (other.gameObject.tag.Equals("Player"))
{
// EnableNextRoom();
// DisableThisRoom();
EnableAndDisableRoom(other);
}
}
public void EnableAndDisableRoom( Collider other)
{
EnableNextRoom();
// Camera.main.transform.position = nextDoor.transform.parent.GetComponent<DoorTeleport>().cameraPosition.position;
// Camera.main.transform.eulerAngles = new Vector3(50, 0, 0); //nextDoor.transform.parent.GetComponent<DoorTeleport>().cameraPosition.rotation;
// Camera.main.GetComponent<CameraFollow>().enabled =false;
// other.GetComponent<CharacterController>().enabled = false;
// other.GetComponent<CharacterController>().enabled = false;
other.transform.position = nextDoor.transform.position;
// yield return new WaitForSeconds(0.1f);
DisableThisRoom();
}
public void EnableNextRoom()
{
// doorSpawn.transform.parent.GetComponent<DoorTeleport>().transform.parent.gameObject.SetActive(false);
var t = nextDoor.transform.parent.GetComponent<NewDoorTeleport>().transform.parent.gameObject
.GetComponentsInChildren(typeof(Transform), true);
for (int j = 0; j < t.Length; j++)
{
if (t[j].gameObject.tag.Equals("Enemy"))
{
t[j].gameObject.GetComponent<EasyStateMachine>().RecycleMachine();
}
t[j].GameObject().SetActive(true);
}
// finalRooms[i].GameObject().SetActive(false);
}
public void DisableThisRoom()
{
// doorSpawn.transform.parent.GetComponent<DoorTeleport>().transform.parent.gameObject.SetActive(false);
bool isTeleportRoom = false;
var t = doorSpawn.transform.parent.GetComponent<NewDoorTeleport>().transform.parent.gameObject.GetComponentsInChildren<Transform>();
for (int j = 1; j < t.Length; j++)
{
if (t[j].gameObject.name.Contains("Minimap"))
{
t[j].GameObject().SetActive(true);
}
else
{
if (t[j].gameObject.name.Contains("Teleport"))
{
isTeleportRoom = true;
break;
}
t[j].GameObject().SetActive(false);
}
}
if (isTeleportRoom)
{
for (int j = 1; j < t.Length; j++)
{
t[j].GameObject().SetActive(true);
}
}
// finalRooms[i].GameObject().SetActive(false);
}
}
Last edited by socker on Fri Mar 18, 2022 12:22 pm, edited 1 time in total.
Re: My script lose reference of another object when load
Hi there,
As there are no warnings, it does not sound like it's because it can't find a reference. In this case it sounds like something is overwriting the variable.
Please could you create a new project with a very simple scene which replicates your issue and private message it to me with step-by-step instructions so I can see what is happening.
All the best,
Joel
As there are no warnings, it does not sound like it's because it can't find a reference. In this case it sounds like something is overwriting the variable.
Please could you create a new project with a very simple scene which replicates your issue and private message it to me with step-by-step instructions so I can see what is happening.
All the best,
Joel
Re: My script lose reference of another object when load
I have a similar problem, did you find a solution?
Re: My script lose reference of another object when load
Hi there,
As this is quite an old thread, please could you make a new thread describing your issue with information about your project. The behaviour mentioned in this post can happen for quite a number of reasons so I would need more specific information to understand why it's happening in your project.
All the best,
Joel
Re: My script lose reference of another object when load
Thank you, I just did hereJoel wrote: ↑Fri Jul 28, 2023 8:11 amHi there,
As this is quite an old thread, please could you make a new thread describing your issue with information about your project. The behaviour mentioned in this post can happen for quite a number of reasons so I would need more specific information to understand why it's happening in your project.
All the best,
Joel
https://moodkie.com/forum/viewtopic.php?t=2875