Error when reverting prefab with serializable array of objects

Issue #46 resolved
Mateusz Małek created an issue

Steps to reproduce:

  1. Create MonoBehaviour class with public array of class objects. For example:
public class MyScript : MonoBehaviour
{
    [System.Serializable]
    public class ArrayElement
    {
        public int IntField;
    }

    public ArrayElement[] Array;
}
  1. Create 2 prefabs: "Child" and "Base".
  2. Add MyScript component to "Child" prefab.
  3. Attach "Child" prefab to "Base" prefab.
  4. Change property "Array" in "Child" prefab - for example change size of the array to 2.
  5. Revert "Child" prefab.
  6. Error "TargetException: Non-static field requires a target" appears in console.

Error appears only when size of the array increases.

As I can see in code issue appears in uPrefabComponentProcessor script, line 212 where copying to new array is made.

Comments (4)

  1. Devon Klompmaker

    @matexpol I cannot reproduce this bug. Can you confirm the following details for me:

    1. Which version of Unity are you using

    2. What version of uPrefabs do you have installed

    3. Can you double check your steps to reproduce

    Thanks!

  2. Mateusz Małek reporter

    Hi! Thanks for the interest and sorry for the delay in my answer.

    I've figured out that I haven't got last version of the uPrefabs, but after updating the plugin, error still appears. Now I'm using uPrefabs 1.8f2 and Unity 5.6.0f3. And yes, I've double checked above steps (with checking on the another PC too) and each time I can reproduce this issue.

    Maybe instead of reproducing the issue, I'll write you what I've done to fix it. Due to my outdated version of uPrefabs, in previous post I wrote you wrong number of the line where issue appears. At the moment in 1.8f2, line 194 you have:

    Array.ConstrainedCopy((Array)targetObjArray, 0, newTargetObjArray, 0, targetObjArray.Count);
    

    and IMHO that causes the issue. If I change this line to something like that:

    Array.ConstrainedCopy((Array)sourceObjArray, 0, newTargetObjArray, 0, sourceObjArray.Count);
    

    everything is ok.

  3. Log in to comment