Missing trees after reloading a project in another folder

Unity version mentioned in this question: 2022.3.

Just for context: Since I started working on a game, I decided to version all the project files on GitHub, except for external assets from the Unity Asset Store. Some of these assets are large, and I have limited repository space, so my strategy is as follows: 1) Once a version is tagged, I back up all the imported assets into a zipped file and save them on a hard drive; 2) I create a new folder on my computer where I check out the versioned files and unzip the external assets there; 3) I open Unity and import it as a new project. This process helps me verify the integrity and ensures I can import this project successfully on another machine if necessary. It’s a bit overwhelming, but it’s been working since day one, so I’ve gotten used to it.

However, in the latest tagged version, when I follow the steps above, I get several InvalidCastException: Specified cast is not valid errors for files like Prefabs/Trees/Conifer/Conifer.st, which come from the Unity Terrain - URP Demo Scene. As a result, all the trees in my terrain are missing!

Curiously, the original project still displays the trees normally and loads perfectly. This issue only appears when I load the project as a new one, which is concerning because both the versioned files and the packed external assets were intended to serve as a reliable backup source.

Do you have any ideas on where I should start investigating the origin of this cast exception?

Thanks!

That means your project on GitHub is incomplete and likely broken.

You’ve been lucky so far. :wink:

You always run the risk of losing references if you externalize them in a non-standard way UNLESS you export them as a .unitypackage. Alternatively, you could wrap the external assets as a Unity npm package, installed via Package Manager.

In the first case you get an already zipped file but you’d have to delete the files in the project after exporting. In the latter case you have a folder that you can zip and delete afterwards.

Problems can still occur with that workflow of course. Consider how much you’re going to have to pay for additional cloud space, and how much getting rid of this overwhelming process is worth your time and troubles. As a general rule, all assets a project requires in order to produce working builds should be in source control.

1 Like

You’ve been lucky so far. :wink:

Yeah, I had the same suspicion. :sweat_smile:

I appreciate the ideas you posted and will try versioning the whole project using Git LFS.

Out of curiosity: should we also version the Library folder inside the project? Given the default Unity .gitignore file provided when I created the repo, it’s ignoring it. However, when I try to load the project without that folder, I encounter the same issue.

No!

Library only contains cached data, eg converted textures, optimized meshes, compiled binaries and such.
Don’t sync anything the default .gitignore excludes.

Interesting. Then the original issue I’m having may be related with that folder. When I try loading the project without the Library, it won’t load those trees, breaking with that console error InvalidCastException: Specified cast is not valid.

However, if I copy the Library folder from a working project, it will load normally.

Well, thanks again for your help. That will definitely give me a direction on where to investigate.

Hmmm that’s odd. Usually it’s the other way around: delete Library, odd issue goes away. :wink:

Check the editor.log for possible details.
You may have to divide and conquer. Copy the project, start stripping it down until the issue goes away to narrow down potential causes.

1 Like