# Geometry Nodes: How Can I Select & Replace A Single Instance?

This question has been asked in various ways but I can't find a specific solution to my problem.

I have created a geonodes "Tile Generator" that tiles 6 objects in a grid with random selection. In this case they are 6 primary colors to illustrate what I'm trying to do...

Using the image below as a reference, how would I replace the one specific instance (the Yellow cube) with a cube that is not part of the instanced collection (in this case the Black cube)?

PROJECT FILE

• Interface: How would you like to tell GN which instance to change? Commented Oct 11, 2023 at 7:19

The implied (used when nothing is connected) input to the Instance Index is just Index. The node then takes the modulo (remainder of division) by domain size, so if you want to have even distribution, you need to make the maximum random number produce the maximum instance index. Assuming the Min is $$0$$ and you have $$6$$ instances, here's some good Max values: $$5, 11, 17, 23, 29, 35, 41, 47, 53, 59, 65, 71, 77, 83, 89, 95, 101...$$ (number of instances multiplied by some integer, minus $$1$$), but of course the most reasonable is $$5$$ (number of instances minus $$1$$).

This might not be visible in this case, but imagine that you have $$100$$ instances, and randomize the index in range $$[0; 100]$$ - the first instance will be picked for both the $$0 \operatorname{mod} 100 = 0$$ and $$100 \operatorname{mod} 100 = 0$$, so the first instance will be twice as common as all other instances.

So here's how you do it correctly:

Then, the most convenient way to introduce the black square is to add it in the beginning of the collection, update the Random node to start at $$1$$ (don't pick the black), and do whatever selection logic you want to resign from a random value and pick the black (index $$0$$):

• Markus I love this solution, it is very precise and works in a way that gives me a lot of control. Thank you! Commented Oct 11, 2023 at 18:01

one possible way is this:

so i just separate the point/instance you wanna replace by index and instance on that a new instance and delete the original point.

• Thanks Chris, I will have to experiment with this. In lieu of not getting my hands dirty with it yet... how do I choose which instance will be selected/deleted? For instance, if I have a grid of 100+ instances? Commented Oct 11, 2023 at 18:03
• @GlenCandle in both are answers the logic for choosing the instance to be replaced is the same: we pick by index. Ultimately you need to choose a logic depending on your needs that you didn't explain: maybe you want to pick a random instance, or an instance closest to a particular point (in which case you would use an attribute statistic first, then separate out the instances that have the distance equal to the minimum in the statistic, then e.g. taking the index 0 of that separated group) etc. Commented Oct 11, 2023 at 18:21
• Thanks @MarkusvonBroady. I have a lot to learn about working with indexes! Commented Oct 12, 2023 at 16:14