うにてぃブログ

UnityやUnreal Engineの記事を書いていきます

【Unity】Parent of RectTransform is being set with parent property. Consider using the SetParent method instead, with the worldPositionStays argument set to false. This will retain local orientation and scale rather than world orientation and scale, which c

Parent of RectTransform is being set with parent property. Consider using the SetParent method instead, with the worldPositionStays argument set to false. This will retain local orientation and scale rather than world orientation and scale, which can prevent common UI scaling issues.

上記の Warning は parent = transform では無くて SetParent を使ってくださいという警告なので

transform.paret = hoge

としている箇所を

transform.SetParent(hoge);

とすればよい

コード

Transform の parent 処理を見てみると以下になっており

setter を呼び出すと Warning が表示されるようになっている

    /// <summary>
    ///   <para>The parent of the transform.</para>
    /// </summary>
    public Transform parent
    {
      get => this.parentInternal;
      set
      {
        if (this is RectTransform)
          Debug.LogWarning((object) "Parent of RectTransform is being set with parent property. Consider using the SetParent method instead, with the worldPositionStays argument set to false. This will retain local orientation and scale rather than world orientation and scale, which can prevent common UI scaling issues.", (Object) this);
        this.parentInternal = value;
      }
    }