- Home /
DragAndDrop.objectReferences won't accept a new array of objects
I am trying to do the following:
DragAndDrop.objectReferences = new Object[1];
It compiles fine, but on execution it just gives:
InvalidCastException: Cannot cast from source type to destination type.
How is this possible? I tried doing:
Debug.Log( typeof DragAndDrop.objectReferences );
And it just printed:
Object[]
So what gives?
Hmm, it's possible the Object type you're using is from the namespace System(.net's Object type) and not UnityEngine(Unity's Object type).
Try:
DragAndDrop.objectReferences = new UnityEngine.Object[1];
Please keep in $$anonymous$$d that the above just initializes an array of type UnityEngine.Object with capacity of 1. Try throwing something that derives from monobehaviour in there, that inherits up from UnityEngine.Object.
Your answer
Follow this Question
Related Questions
Limiting Drag and Drop 1 Answer
Spawn object with different material. 0 Answers
Array of GameObjects 4 Answers
How to drag and drop any object to any empty space? 0 Answers
Removing objects from an array 2 Answers