Skip to content

Instantly share code, notes, and snippets.

@AldeRoberge
Created February 15, 2024 19:15
Show Gist options
  • Save AldeRoberge/be59701ce26160d28c00751988a4325c to your computer and use it in GitHub Desktop.
Save AldeRoberge/be59701ce26160d28c00751988a4325c to your computer and use it in GitHub Desktop.
Find broken managed references in Unity caused by [SerializeReference], projectwide search for the GUIDs
# The provided script is designed to be useful for identifying broken references caused by the [SerializeReference] attribute in Unity. In Unity, when creating a prefab for a script in a scene, old values may persist, potentially disrupting the SerializeReference mechanism and leading to errors during scene opening or building. The script helps locate and identify broken .asset (YAML) references in the Unity project.
param (
[string]$searchDirectory = "C:\Users\Alde\Documents\GitHub\Wikwemot-AR\Wikwemot-AR\Assets",
[string]$searchString = "6945820829875175427"
)
function Search-FilesForString {
param (
[string]$directory,
[string]$searchString
)
Get-ChildItem -Path $directory -Recurse -File | ForEach-Object {
$filePath = $_.FullName
$content = Get-Content -Path $filePath -Raw
if ($content -match $searchString) {
Write-Host "Found in file: $filePath"
}
}
}
# Check if the specified directory exists
if (Test-Path $searchDirectory -PathType Container) {
Search-FilesForString -directory $searchDirectory -searchString $searchString
} else {
Write-Host "Error: The specified directory '$searchDirectory' does not exist."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment