Hi, getting build ready for Steam and encountered an issue when switching scenes quickly back and forth. Doesn't always happen the first time, most often happens on third or fourth time switching scenes quick.
I ended up reverting back to an early build to see if it was still there before I added Steamworks and stuff - still there.
Always related to "NullReferenceException: Object reference not set to an instance of an object"
Also tried updating to the latest version of AC to see if error went away, but same result.
Including some screenshots in case there's a solution for this or best practices I'm not following.
proje
[EDIT: Addition, I tried the earlier web build that's publicly out on itch.io and couldn't recreate the crash. Not sure what would have happened between now and April after opening the project]
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
The one thing I did change was a suggestion from someone else, making the audio controlled by mixer channels and using snapshots at the start of every scene to set levels... I wonder if that did anything to break things?
Another clue perhaps - I'm trying to use GitHub to prevent disaster, but am fairly certain it'll cause disaster with conflicts etc. and my incorrect use of it. I saw this when pulling from an earlier version:


Yeh. Tried my older build - weirdly, I can trigger the crash consistently even in the old build, so I think it was probably always there, just never discovered.
I tried getting some info from an LLM, says that if scene transitions happens very quickly, things might not have time to be initialized, so maybe that's the issue.
Would love to know any insights / if there's a solution I should be looking at. Though I've tried setting an Engine: Wait period at the start of OnStart Action Lists and that didn't help.
Oof, dunno what I've done. Now even if I switch between the same 2 scenes not even quickly, I get the same crash error:

I did see the same error about a prob while importing the MainCamera.prefab on project startup.
Hmm... getting a lot of crashes and errors on my old build I've never seen before, not quite sure what to make of it. This happens if I try move my character between two other scenes a couple times fast.

Using AC 1.82.2. Should I maybe try re-download the asset if possible? I'm a little worried some of the stuff I've used in my game (like edited cursor manager etc) from the AC folder, so I'm worried of breaking/losing links to even more stuff by doing so.
Sorry to keep updating here, but I'm super stuck. Now, almost every time there's a scene switch, even on my old build that worked pretty flawlessly beforehand, I get a crash, with the 'NullReferenceException: Object reference not set to an instance of an object' error.
Here's some more crash errors when entering another room, the shop:

If I load up the shop from scratch in the editor it works fine, but if I leave and come back, it crashes.
In case helpful, I downloaded a ZIP of the entire Unity game project I backed up on Google Drive in April, and added it to Unity. When opening it, there were about 30 security messages with packages I had to manually allow in security settings for Mac, a lot of packages and .dll that Mac thought could be malicious
.
Anyways, same story - crash on scene change, and weirdly, the crash error is looking in a directory I used to use for the game originally. The files are still there, but that's definitely not the local directory I'm using for the downloaded project, I put the downloaded project on another drive but is still looking at the old directory for the StateHandler script.
Ah, now is showing the local path error.

Hmm. I really hope this is solvable. Loaded up the 2D Demo to see if anything looked obviously different, doesn't look like it. Checked the components on the Persistent Prefab engine, all look the same. Without catastrophising, I don't think I'll be able to start from scratch to recreate the game.
Not sure if my probs started when I handed the project over to someone who kindly offered to work on some sound updates and then my machine got confused when I had a second project back to try work with, or if it's something else I can't think of. But, the same issues are even happening now with my old version before I shared it.
I don't think it's because Unity is using a different build, it looks like I just have one build installed, Unity 6 26f1, so I don't think that's it.
Hmm... here's hoping this is solvable. I'm stumped, tried a bunch of stuff like moving player starting positions between scenes and whatever other suggestions I could find on the forums, I think the game managers are all set correctly, nothing looks weird there.
LLMs suggest something's like a kickstarter is not being initialised soon enough which is leading to the null object error, but I never had this issue when working on the game from Jan-April this year, so I'm almost certain something's gone awry, and I just don't know what.
Out of interest I tried starting a fresh project with the latest version of AC. I duplicated the 2D Demo park scene and walked Brain between the 2 scenes quickly. I didn't get a crash after repeatedly doing that, and no errors. No idea what's gone awry with my own project.
After asking an LLM to explain it to me like really simply, I think (hope) I figured it out - I think it was all the triggers I had. I had a bunch of triggers on the ground running continuously that would run action lists if the player character performed a certain action in them, as well as triggers that would change footstep sounds.
I deleted all of them in the troublesome scenes in both my old and new project, and it seems to have solved it. Going to do more testing later to dig deeper and see if that really is the issue, but initial tests look positive.
May I ask please - what's best practices way of setting footstep sounds depending on where a player walks? Clearly the large trigger areas I had that were 'continuous' weren't working well / weren't efficient, and I think it's because I had some of them set to 'able to interrupt self or cutscenes' so Bru could dab and trigger a response from a nearby character, that messed things up.
It does look like the use of Triggers is the root cause, though this shouldn't result in such an error.
The original NRE error can be fixed by opening the StateHandler script and finding the gameState property block around lines 549-577, then replacing:
with:
The method of changing footstep sounds was changed in v1.81. Previously, it was a case of using the Sound: Change footsteps Action to manually set the sound.
This Action can still be used to set the character's current Surface, but the intended method is to use the Footstep Sounds component's Auto-detect Surface? option and use raycasting to detect a Collider's Physics Material 2D asset whose name represents the Surface.
Details of this can be found in the Manual's "Footstep sounds" component, but it may be that the script change above is enough.
Thanks Chris. I did try the new code, but was still getting crashes.

Only way that works for me seems to be to disable or remove the large footstep area triggers. I'm not sure why this would be happening now and not earlier, but at least I can carry on working on the project.
The new error is as such:
[edit: sorry, this is the wrong error, the one I wanted to capture was about a footsteps trigger and couldn't start coroutine, after I tried the new code]
NullReferenceException: Object reference not set to an instance of an object
AC.StateHandler.get_gameState () (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:564)
AC.AC_Trigger.IsObjectCorrect (UnityEngine.GameObject obToCheck) (at Assets/AdventureCreator/Scripts/Logic/AC_Trigger.cs:346)
AC.AC_Trigger.OnTriggerExit2D (UnityEngine.Collider2D other) (at Assets/AdventureCreator/Scripts/Logic/AC_Trigger.cs:158)
I think the auto-detect surface may be a little complicated for my uses, but will keep experimenting with the action, it may be eg that it's the 'continuous' setting that's shanking things and may work better with 'enter' or 'exit'
What is on line 564 of your version of StateHandler.cs?
Hi Chris - it's this:
if (KickStarter.playerInteraction.InPreInteractionCutscene) return GameState.Cutscene;
I do have another question please that I was using triggers for - I had the player able to press a button to 'DAB' once they learned the ability, and if they were inside the trigger area of an NPC, that would trigger an actionlist where the NPC would say dialogue eg 'Wow, cool' or whatever.
It wouldn't always work, and I suspect some of the gnarliness came from those triggers set to 'continuous' and 'interrupt self' and able to play in both 'gameplay and cutscenes'.
Is there a better way to set something like that up? I may remove it from the Steam game if it causes issues.
From what I can tell, small trigger areas seem ok, so I might try set up footstep changes with small little rectangles set to trigger on enter or exit, instead of the sprawling 'continuous' ones I had that overlapped other hotspots.
Replace that line with this:
Likely Continuous combined with "Interrupt self?" are causing issue - since that would cause the ActionList to re-run each frame the Player is inside it.
On Enter is typically better to use where possible. Bear in mind that you can attach another AC_Trigger component to the same Trigger object, and set it to On Exit, to have it react to the same bounds as the first component. This can be useful sometimes if you need to have an on/off switch based on the Player's position.
Hi Chris, thanks I tried this new script replacement, but unfortunately the same result of crashing.
It seems that if I have any triggers with more than one Trigger component (eg one for enter and one for exit), or 2 triggers overlapping each other, one for enter and one for exit, this results in a crash when moving between scenes.
The good news is, I seem to reliably (with my testing thus far at least) trigger footsteps like so, with a 'change footstep' trigger and then surrounding it with other 'change footstep' triggers, all set to 'on enter'. Not the most elegant solution, but it works.

I've had a look at the 1.83 manual for the recommended way to set footstep sounds a couple times, but couldn't get my head around it. It sounds like firing raycasts at the characters feet and auto-detecting material colliders would be more suited to 3D games? Would it be a case of creating a new GameObject, giving it a PhysicMaterial component or something, maybe with a polygonal collider, and giving it a name of eg 'Sidewalk_Grass' or 'Bathroom_Tile'? I'm not quite sure how to set it up, how to give it a PhysicMaterial asset, or where to use the suggested _ naming convention
I've had a look at the Unity doc about PhysicMaterial (I think Unity must have moved the link to a new one, the manual goes to a missing page)
https://docs.unity3d.com/Manual/create-apply-physics-material.html
Unity mentions linking the material to a collider. In AC terms, would this be a hotspot?
Thank you.
Firing raycasts is viable in both 2D and 3D - but with 2D, you'll want to use Physics Material 2D assets - the 3D equivalent of PhysicMaterial (now correctly named Physics Material in Unity 6).
It doesn't involve AC component - just place a 2D Box Collider on the Ignore Raycast layer, check Is Trigger, assign the material, and that should be eough.