Neat Bug/Feature

The way that I have my cut scene set up I have a neat Bug or maybe I will call it a Feature. Since my roaming guards are kind of important to the cutscene I actually have them set to be disabled in the scene, I then use a Timeline Activation Track to enable them. This has created a bug that when I exit the scene and come back that the roaming guards will always go back to their original state.

https://imgur.com/a/kRRWO4f

I can fix this by making a paroling guards game object for the cutscene and have that activate just for the cutscene while deactivating the in game paroling guards.

I might just call this a feature and leave it for now, maybe go back and change it later if I add an Enemy Spawner that will spawn guards in the scene automatically after a set time if the guard is dead. Or some other feature that brings the guards back to life. This gives the level some replay-ability if you leave and come back latter.

This may be because if they’re beginning in an inactive state in the scene, the SavingSystem may not be picking them up in RestoreState()

I believe you are right, I believe that the restore state only picks up objects that are active when it is called. The components on a Game Object are disabled if the Game Object itself is Disabled. I believe there is a way to have the Components run even if the Game Object is not Active, it has been awhile. I have several options to fix this bug. This is not a bug with Unity as this is the expected behavior for Game Objects, it is a Bug with how I am currently Implementing things.
1.) Make the Game Objects need for the Cut Scene to display the way I want cutscene objects and disable the Game play Objects (probably the easiest solution)
2.) Get all of the Game Objects in the scene that are currently inactive, activate them, Load them, then Deactivate them. Maybe I will also save there active state and only Deactivate the ones that are not active when the game loads. This might be the better solution as this will allow me to have objects that are not active activate with some sort of trigger for game play.
3.) Do some research on having a deactivated Game Object still run Components, not a solution for me as the reason that I activate these in the in the Timeline is to ensure that they are in the correct position to be seen in the cut scene.
4.) Change the way the AI behaves, have it change to the patrolling state when an event occurs.
5.) Call the Bug a Feature, and know that this is an issue that may cause an issue latter on if I add some sort of other Core Game Play Mechanics that have an object start off deactivated in which case I will have to implement a fix.

Even thou this is technically a Bug in the Game, the Players will not notice it as a lot of this style of games have enemies that reappear when you return. This is a feature that I want in the Game and was going to implement later after I completed everything else, at least now I have some what of a Feature that I want in the game without actually having to create that feature.

I actually realized I knew the solution…
In SavingSystem.RestoreState and CaptureState, in the foreach loop, add the parameter true to the FindObjectsOfType

 foreach (SaveableEntity saveable in FindObjectsOfType<SaveableEntity>(true))

This will instruct FindObjectsOfType to consider inactive GameObjects as well.

1 Like

That’s it I knew that there was something like that I just couldn’t remember, it’s one of those have to look into the code that was being used and remembering to see what the other overloads are. I hadn’t actually dug through the code that the saving system was using yet. I just might make that change later on if I need it to consider inactive GameObjects down the road. Or better yet I just added a private Serialized Field bool to the Saving System that I can toggle in the inspector if I need that behavior. Passing the value of that bool to the Find Objects of type.

Privacy & Terms