Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TryGetComponent に書き換え #2380

Merged
merged 8 commits into from
Jul 25, 2024
Merged

Conversation

ousttrue
Copy link
Contributor

@ousttrue ousttrue commented Jul 24, 2024

エラー

attach されていない場合でも is 演算子が true になって後続で例外になる

MissingComponentException: There is no 'Animator' attached to the "Seed-san" game object, but a script is trying to access it.
You probably need to add a Animator to the game object "Seed-san". Or your script needs to check if the component is attached before using it.
UniGLTF.HumanoidValidator+<Validate_TPose>d__6.MoveNext () (at Assets/UniGLTF/Editor/UniGLTF/Validation/HumanoidValidator.cs:145)
UniGLTF.ExporterDialogState.Validate (System.Collections.Generic.IEnumerable`1[T] validators) (at Assets/UniGLTF/Editor/UniGLTF/ExportDialog/ExportDialogState.cs:105)
UniGLTF.ExportDialogBase.BeginGUI () (at Assets/UniGLTF/Editor/UniGLTF/ExportDialog/ExportDialogBase.cs:104)

再現手順。

vrm-1.0 の seed-san vrm の拡張子を glb に変える。
glb として import して、prefab をシーンに展開。
VRM-1.0 の export dialog に投入する。

備考

UnityのGetCompornent()でNull条件演算子が使えない
に類似する問題と思われる。

#2319 と現象が似ている。
Validation で繰り返し例外が発生してしまう。

@ousttrue
Copy link
Contributor Author

null_error

@@ -137,7 +137,7 @@ public static IEnumerable<Validation> Validate_TPose(GameObject ExportRoot)
{
getBoneTransform = humanoid.GetBoneTransform;
}
else if (ExportRoot.GetComponent<Animator>() is Animator animator)
else if (ExportRoot.GetComponent<Animator>() is Animator animator && animator != null)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

とりあえずこれで直るのだけど、他の場所にもありそう・・・

Santarh
Santarh previously approved these changes Jul 24, 2024
Copy link
Contributor

@Santarh Santarh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この目的なら TryGetComponent<T> が良いと思われます

https://docs.unity3d.com/2021.3/Documentation/ScriptReference/Component.TryGetComponent.html

@Santarh
Copy link
Contributor

Santarh commented Jul 24, 2024

間違えた、Request Changes です

@ousttrue
Copy link
Contributor Author

ついでなので、他の場所も TryGetComponent に書き換えます。

@ousttrue ousttrue changed the title attach されていない場合でも is 演算子が true になって後続で例外になる [WIP] TryGetComponent に書き換え Jul 24, 2024
TryGetComponent
GetComponentOrThrow(拡張関数)
GetComponentOrNull(拡張関数)

sample と test は据え置き
@ousttrue ousttrue requested a review from Santarh July 24, 2024 13:11
@ousttrue ousttrue changed the title [WIP] TryGetComponent に書き換え TryGetComponent に書き換え Jul 24, 2024
Animator.GetBoneTransform のために GetComponent しているところの Export Error を修正するついでに、
Animator.GetBoneTransform と Humanoid.GetBoneTransform 両対応とした(vrm-0.x と vrm-1.0 両方)。
Copy link
Contributor

@Santarh Santarh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


if (vrmMeta == null)
if (root.TryGetComponent<Vrm10Instance>(out var vrmController))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

リファクタ系の PullReq はリファクタだけにしてもらえると、 diff を読む時間をかなり減らせてうれしいです

@ousttrue ousttrue merged commit bad27a5 into vrm-c:master Jul 25, 2024
1 check passed
@ousttrue ousttrue deleted the fix/null_component branch July 25, 2024 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants