[BUG] [Unsolved] Error : "You may not pass"

Hello.
I’m using MacOS with Unity 6000.0.30f1, but
I’m keep receiving this annoying error:

You may not pass in objects that are already persistent
UnityEngine.StackTraceUtility:ExtractStackTrace ()
UnityEditorInternal.InternalEditorUtility:SaveToSerializedFileAndForgetInternal (string,UnityEngine.Object[],bool)
UnityEditorInternal.InternalEditorUtility:SaveToSerializedFileAndForget (UnityEngine.Object[],string,bool) (at /Users/bokken/build/output/unity/unity/Editor/Mono/InternalEditorUtility.bindings.cs:271)
UnityEditor.Build.Profile.BuildProfileContext:OnDisable ()

Although this error occurs, everything works quite well.
But I wonder why Unity Engine is keep throwing this error out of nowhere.

For your information, with Unity 2023, this error only occured after a force quit and relaunch.

1 Like

It could be because you have at least 2 scripts with DoNotDestroyOnLoad method on the same GameObject. I also heard that it could be issue and with Build Profiles but I think that is unlikely.

Yes, right now it is Holiday and I am coding alone in my room by day and night.

1 Like

I’m getting the same thing, are you able to find any info on the object that’s causing it? I can’t so it looks like it’ll have to stay :confused:

I had the same issue after importing a model from the asset store. Fixed it by doing Assets → Reimport All (in the Project window), Unity fully reloaded the project and the error was gone.

1 Like

consistently having this issue with Unity 6000.0.23f1, reimporting all assets works but only until the next opening of the project, so its not a solution.

Error occurs on every domain reload.

It’s very annoying to see an error appear on every domain reload.

1 Like

On Windows with version 6000.0.26f1 and just ran into this problem too after opening a fairly big project to make a WebGL build.
Reimporting all assets fixed it enough for me to at least make the build.

Same issue, I don’t have DoNoDestroyOnLoad methods on any of my scripts on any gameobject, so that is unrelated.

Opening a clean project and letting it reimport the library and recreate all the objects folders does not generate this errror, subsequent openings of the project will spam this message throughout my usage of Unity, builds are fine, player runs fine, its just some Unity bug with build profiles I’m sure. They had one at the start of Unity 6 with localization files as well, they just need to put the time in to investigate this one.

“Opening a clean project and letting it reimport” DOES generates MORE errors…
so annoying

[SecuritySafeCritical]
	[RequiredByNativeCode]
	public unsafe static string ExtractStackTrace ()
	{
		int num = 16384; // num = 16384
		byte* ptr = stackalloc byte[(int)(uint)num]; // allocation to stack
		int num2 = UnityEngine.Debug.ExtractStackTraceNoAlloc (ptr, num, projectFolder); // extracting stack trace with no allocation, with buffer mx value 1638, from project folder
		if (num2 > 0) {
			return new string ((sbyte*)ptr, 0, num2, Encoding.UTF8); 
// new string, pointer(16384) starting from index 0, UTF8 encoding
// so basically return stacktrace from project if it exists.
		}
		StackTrace stackTrace = new StackTrace (1, fNeedFileInfo: true); // or, just skip 1 frame and make new instance
		return ExtractFormattedStackTrace (stackTrace); // than extract formatted stack trace and return
//but this isn't related to this error as it returns formatted string such as : "MonoBehaviour : Unknown error"
	}

This happened to me in version 6000.0.32f1 after creating and then removing a custom build profile.

I solved it by deleting the ‘Build Profiles’ folder that’s within the ‘Library’ folder of my project. I think removing the profiles in-editor does not remove them from your project automatically, just a guess though.

2 Likes

In my experience, “You may not pass in objects that are already persistent” typically happens when I mistakenly accessed a prefab itself in the asset folder, not an instance of a prefab.

Then I had this error on my project(Unity 6000.0.2xxx, forgot the version) all of sudden,
spent a few hours trying to figure out where I made incorrect references to prefab assets but didn’t find any.

As a last resort, uninstalled the existing version of Unity and installed 6000.0.39f1, I don’t have the error anymore.

I just upgraded from 6000.0.40f1 to 41f1 (after upgrading from 2021->2022->6000.35f1->36->37->38->39->40 without issues) and then suddenly started getting this error twice followed by:

ScriptableSingleton already exists. Did you query the singleton in a constructor?
UnityEditor.ScriptableSingleton`1<Unity.ProjectAuditor.Editor.ProjectAuditorSettings>:.ctor ()
Unity.ProjectAuditor.Editor.ProjectAuditorSettings:.ctor () (at ./Library/PackageCache/com.unity.project-auditor@ddf0087c8d85/Editor/API/ProjectAuditorSettings.cs:24)

and then followed once more by the “already persistent” error.

I’m not even using any scriptable objects.

I deleted the “Library\Build Profiles” dir and now all 3 “already persistent” errors are all gone but still getting the ScriptableSingleton error when I load the project or press Play.

Update: Rebooting the “persistent” errors came back but the other one went away. Reloading the project there are either 3 errors or no errors.

I having this issue too!
I using Unity 6000.0.32f with Photon Network
and I don’t know why…

I used to asked ChatGTP about this and they said…
it because of DontDestoryOnLoad somewhere
so I decide to remove all DontDestroyOnLoad method everywhere

But the error still remaining…

In summary, DontDestroyOnLoad being used twice or more on the same object causes this error.

even if you remove all DontDestroyOnLoad, you WILL still get errors if your are using some assets from asset store or something like that,

I suppose.

I having same issue too,
I using Unity 6000.0.32f1 and Photon Network
even I remove all DontDestroyOnLoad!
But this error still having…

If error does not affect any of your game, just ignore it. You do not have to remove all DontDestroyOnLoad methods. The error could be caused by two things:

  1. DontDestroyOnLoad method used in two scripts that are attached to the SAME gameObject in your scene. (Keep in mind that DontDestroyOnLoad works for whole gameobject and all components attached to it, will presist, it solved the error for me)
  2. Build profiles. Remove build profiles and if it solves the problem, it means it does not affect anything, you can just ignore the error or choose not to have any seperate build profiles.

My project uses ScriptableSingleton. I solved this problem by overriding its Save method. Before overriding, calling Save(bool saveAsText) would trigger an exception “You may not pass in objects that are already persistent”.

Updated to 6000.0.47 and it has finally stopped

Deleting “Library\Build Profiles” and reloading the editor fixed my issue. I believe this started happening after the new separate build profiles changes when I started using a custom build profile (android, in my case)

Had this error as well and can confirm it was related to a new build profile I had created. Deleting it from the File > Build Profiles menu and then restarting Unity fixed it for me. On a Mac btw (and was using a custom Windows build profile)