Getting triggers to stop triggering on some objects once certain criteria is met

Hi. Apologies for the weird question title, found it really hard to sum up in a sentence.

I’ve a game at the moment where you need to place books onto a shelf, upright. This is done with triggers; when you drag a book into the trigger area and drop it, if it stays upright it’s marked as correctly placed and the trigger material turns green. That is all done in OnTriggerStay. And then in OnTriggerExit, the material colour goes back to normal once the book is moved out of the area, and it’s marked as nothing being placed there.

The above is working. But when a book is correctly placed, and then I try and drag another book into the trigger area, and then out again, it’s marked as nothing being correctly placed there, despite the original book still being placed there — I have to click the correctly placed book for it to marked as placed. I’ve tried a check by saving the gameobject that’s correctly placed, and then making OnTriggerExit only fire when that book exits, but I can’t get it to work. (this isn’t in the code below, but the gameobject being saved is ‘book’, which still is)

Has anyone any ideas?

// EDIT
I’ve since recoded some parts, so putting them below. But the issue seems to be something to do with how close the object are to each other; see my comment below.

void OnTriggerEnter(Collider col){

		if (col.gameObject.tag == "Draggable"){

			//print ("Enter col: " + col.gameObject);
			
			objectAttemptingEntry = col.gameObject;
		}

		if (bookPlaced && objectAttemptingEntry != objectPlaced) {

			ignore = true;
		}
		else {

			ignore = false;
		}
	}

	void OnTriggerStay (Collider col) {

			if (col.gameObject.tag == "Draggable"){


				if (!ignore){

					//print ("staying col: " + col.gameObject);

					objectAttemptingStay = col.gameObject;

					if (objectPlaced == null || objectPlaced == objectAttemptingStay){


						if (objectPlaced == null){
							print ("Object Placed is Null. " + objectAttemptingStay + " is attempting Stay");
						}

						if (objectPlaced == objectAttemptingStay){
							print ("Object Placed is objectAttemptingStay. " + objectAttemptingStay + " is attempting Stay");
						}

						GameObject temp = objectAttemptingStay;

						DraggableItem item;
						item = temp.GetComponent<DraggableItem>();

							// check the orientation of the book type to see if it's close enough to be correct, depending on the orientation specfied above
						if ( 	(CloseEnough(temp.transform.rotation.x, orientationF_up_A, 0.5f)) 
					  	  	||  (CloseEnough(temp.transform.rotation.x, orientationF_up_B, 0.5f)) 
					   		||  (CloseEnough(temp.transform.rotation.x, orientationF_down, 0.5f)) ){

							// correct book, correct orientation
							gameObject.renderer.material.color = Color.green;
							bookPlaced = true;
							item.inPlace = true;

							objectPlaced = temp;
						} 
						else {
							// correct book, wrong orientation
							gameObject.renderer.material.color = Color.red;
							bookPlaced = false;

							item.inPlace = false;
						}
					}
					else {

						objectAttemptingEntry = null;
						//objectAttemptingStay = null;
					}
				}
		}
	}

	void OnTriggerExit (Collider col) {

		if (col.gameObject.tag == "Draggable") {

			//print ("Exit col: " + col.gameObject);

			objectAttemptingExit = col.gameObject;

			if (objectAttemptingExit != objectPlaced){

				print ("objectAttemptingExit is not the placed object. Returning");
				objectAttemptingEntry = null;
				objectAttemptingExit = null;
				return;
			}
			else {

				if (objectPlaced){


					print ("objectAttemptingExit is objectPlaced. Exiting.");

					DraggableItem item;
					item = col.gameObject.GetComponent<DraggableItem>();
						
					gameObject.renderer.material.color = Color.white;
					bookPlaced = false;
					item.inPlace = false;
					objectPlaced = null;

					objectAttemptingExit = null;
					objectAttemptingStay = null;
				}

			}
		}
	}

I eventually scrapped all this code and redid it with a spherecast. Now instead of a trigger checking for books, a spherecast comes out of the trigger area and does the job.

As I couldn’t get this to work with Triggers in the end, this doesn’t really answer my question, so I won’t mark this answer as correct. If someone could figure out an answer the actual question, I’ll happily mark it.

From what I could figure out, it’s something to do with proximity of the two objects. When I moved an object close (how close or not doesn’t seem to be a constant figure) to a correctly placed object (whether their colliders overlapped or not didn’t seem to matter), then the correctly placed object’s OnTriggerExit function would call; despite there not being any movement to that object. This happened whether the object being moved (ie, not the one correctly placed inside the trigger) entered the trigger area or not.

Makes no sense to me anyway. Maybe it’s a Unity bug, or maybe I was just missing something.