|
The below code is a snippet of a test of what I'm trying to do. I know it isn't working as intended and I'm getting a "Destroying assets is not permitted to prevent data loss error". What I want to do is to have an array of instantiated GameObjects which I can then manipulate by accessing said array. Anyone have any tips on how I could accomplish this? Thanks in advance. OLD array declaration.... NEW array declaration....
Okay, after some experimentation on my end, I found that if i declare the array as an Object array instead of a GameObject array the operation
works correctly. However, I now cannot access any of the functions that I would have had access to(namely .tag and .transform). I'm not exactly sure of how to go from here...
(comments are locked)
|
|
Problem solved, an explicit casting cleared up all issues, thanks to all who commented. solution: declaration...
casting...
(comments are locked)
|

Do you mean that you want to destroy all gameobjects in the array or the array itself? Have you tried a forloop? :)
My intention is to selective destroy elements in the array, and shift new items into those elements. The algorithm is designed, I just made an assumption as to how this would be handled that turned out to be incorrect.
An array completely sucks for what you want to do. Use a List.
"shift" was perhaps an incorrect term to use as I will not actually be doing a linear shift. The order of operations will be: destroy gameobject, raycast to find object that will (physically) shift into that position, shift the transform of the new object, assign the new object to the old object's index, then null the index it originally occupied. I suppose a triply-linked list could do the job, but there would be more operations than I'd like in its execution.
Don't write "solved" in the title, mark the answer as accepted.