0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Unity] Git LFS対応したリポジトリのカスタムパッケージでファイルが正常に読み込めないとき

Last updated at Posted at 2025-09-08

概要

Git LFS 対応したリポジトリをカスタムパッケージとして公開するときは、 .gitattribute ファイルを package.json のあるフォルダに置きましょう。
そうしないと、読み込んだ側のプロジェクトで正しくファイルをクローンできません。

経緯

とあるUnityプロジェクトで自作のパッケージを定義して、別のプロジェクトで読み込ませています。このプロジェクトをGit管理にして、LFS設定したところ、読込先でLFS化したファイルを読み込むとエラーがでました。

Could not create asset from Packages/.../3e3d.png: File could not be read

一応ファイルができてるのですが、中身がテキストでいわゆる LFSポインタのままになった状態です。

解決法

UnityのパッケージマネージャーはLFSに対応しています。

ただし、PCにGit LFSがインストールされている必要があるとのこと。

じゃあなんでダメなのかと調べたらこんな記事がありました。

For anyone arriving here, the workaround (still) is to copy/move your .gitattributes to the same folder as package.json, as per: Unity Issue Tracker - Package Manager fails to download LFS files from Git repository when the Git URL contains a path extension

冒頭に書いたように、 .package.json と同じフォルダに .gitattribute ファイルを置けということです。自分でLFS設定した人ならご存じでしょうが、もちろんこの .gitattribute はLFS化ファイルのパターンが定義されたものでなくてはなりません。

中身はこんな感じです。

.gitattribute
*.png filter=lfs diff=lfs merge=lfs -text
*.ogg filter=lfs diff=lfs merge=lfs -text
*.mp4 filter=lfs diff=lfs merge=lfs -text
*.mp3 filter=lfs diff=lfs merge=lfs -text
*.wav filter=lfs diff=lfs merge=lfs -text
*.ttf filter=lfs diff=lfs merge=lfs -text
*.OTF filter=lfs diff=lfs merge=lfs -text

この .gitattribute を元プロジェクトにpushして、読込先でパッケージマネージャーの更新をかけたら、正常に読み込めました:thumbsup:

参考:

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?