Closed OvercastInteractive closed 4 days ago
Welp, another one of these saving/loading problems.
Looking into this but so far it seems trickier than I thought. I've tried saving and loading an array of NodePaths, but the save system can't store whole arrays (or at least not in a straight-forward way) so i might have to figure out a workaround.
I've added some code to at least prevent crashes when transitioning to level scenes with enemies in them, see https://github.com/Phazorknight/Cogito/commit/5182d7ad93e02ed3ff3b4beafbb2bc089e3082f4
Will look into this more but for now at least this prevents crashes.
Okay, I've changed the implementation of patrolling a bit to make this work in https://github.com/Phazorknight/Cogito/commit/e96be850e44fe03654708a61f507019b598e87b0:
There's now a script that can be attached to a node called cogito_patrol_path.gd
which holds the Node3D Array to the patrol points.
You can set a reference to a cogito_patrol_path in your enemy's inspector and this reference is saved and loaded as expected.
@OvercastInteractive pls let me know if this resolves this issue for you.
I'm seeing a different issue now, the patrol_points array isn't getting initialized on load so it throws an error when attempting to get the array's size.
My basic workaround just assumes all the patrol points are children of the patrol path node and are added on ready:
Oh that's really odd. When exactly does this error happen? On testing the level scene directly? or when/after transitioning?
As the CogitoPatrolPath node is part of the level scene, it should always be available before the enemy gets loaded...
I personally don't want to dynamically add the patrol points to the array as I want to be able to re-use points between different paths and also leave it open to change their order within the array.
My reproduction steps:
@OvercastInteractive thanks for this. I've realized that this issue is caused by the order in which godot loads nodes/scripts.
Please see https://github.com/Phazorknight/Cogito/commit/6c396f598a83ce757492510e9302c123a4fd5a7b for my attempt to fix this and hopefully improve robustness to the enemy script in general.
Good to know, I've come across similar cases in my own projects in regard to script call order. Your changes look to have fixed this issue, thanks!
Awesome, closing this.
Cogito and Godot Engine Version: Godot: 4.2.2 Cogito: beta 202409.02
Description: Saving in the Lobby before entering the Laboratory breaks the enemy's patrol points.
Reproduction steps:
Expected behavior: Enemy patrol points are saved or unaffected by scene changes.
Screenshots: