How can I move a GameObject from a Level array to a Player array?

First, thank you for taking the time to read this. I am new to Unity, and I am trying to build a puzzle game. I’ve got the Level and Player being built, and the unique player motion is working, and the whole project is close to a playable Alpha thanks to Unity.

My problem is that after the Level puts in an object for the Player to pick up and move, when the Player picks it up, instead of going with the Player, the Player seems to get a copy and the Level item stays with the Level. Both the Level and the Player use GameObject arrays, using [ (Y*width)+X ] indexing for the position of the object. The Level also uses an int grid that is used to track contents.

To take the item from the Level, the Player calls this TakeItem:

public GameObject TakeItem(int X, int Y) {
	grid [(Y * GridWidth) + X] = 0;
	GameObject ret = Instantiate(levelItems [(Y * GridWidth) + X]) as GameObject;
	Destroy (levelItems [(Y * GridWidth) + X]);
	return ret;
}

But this just makes the object disappear, and the Player has nothing. Without Destroy, the player has a copy, but the Level still has the object.

I also tried:

public GameObject TakeItem(int X, int Y) {
	grid [(Y * GridWidth) + X] = 0;
	GameObject ret = levelItems [(Y * GridWidth) + X];
	levelItems [(Y * GridWidth) + X] = null;
	return ret;
}

…but I can’t seem to get the GameObject to go with the player, AND NOT stay on the Level. Either it is in both places, or it is gone completely. I’m confused.

I found the actual problem: two Level objects were instantiated, causing two get-able objects in the scene, but the Player only connects with one of the Level objects, so it only took one, while the other Level object continued displaying it’s untaken object.

@hexagonius and @GameDevBryant , the callee placed the reference into its own GameObject array directly:

contents [0] = currentLevel.TakeItem ((int)topLeft.x, (int)topLeft.y);

and subsequent movement properly translated the taken object.

And thank you for verifying that I was on the right track in the first place, I just ended up looking for the bug in the wrong place. I was starting to wonder if I “think in C++” too much, and was missing a nuance of C# somewhere.