- Home /
Instantiated (clone of) prefab, doesn't trigger another object's collider when inside it.
When certain things happen, I have a prefab (objectA - the prefabs clone that gets instantiated) instantiated at the position of an empty gameObject (objectB) with a collider component that works as a trigger.
Generally, when any object enters objectBs collider, objectBs tag changes to something and when the other object exits objectBs collider, objectBs tag reverts to its initial value (see js below).
The problem is that when the objectA gets instantiated on objectB, objectB doesnt seem to "notice" it. I hit pause and select objectB in the Scene view and verify that its tag has remained unchanged, even though objectA (the prefabs clone) has entered objectBs collider.
Whats strange, is that when I touch objectBs (as I said, this is the empty game object with the collider) translate gismo (the game is paused still), the tag immediately changes as it was supposed to. The objectBs position doesnt change when I do this, maybe just one or two tenths of distance units, but the malfunction definately has nothing to do with my colliders not being inside one another - I made objectAs collider big enough.
Does anyone have an idea why this happens?
The script that's attached to objectB and controls its tag, depending on whether another gameObject is inside its colliders boundaries or not is the following simple js:
function OnTriggerEnter(other : Collider) { gameObject.tag = "VacancyTesterFull"; }
function OnTriggerExit(other : Collider) { gameObject.tag = "VacancyTesterEmpty"; }
Answer by schwertfisch · Jan 10, 2011 at 09:45 PM
Being a Unity novice, I hadn't attached RigidBody component to objectA and that caused the problem. Thanks again Tuck for bothering to answer :)
(I'll have to wait a day before checking my own answer)
Answer by Tuck · Jan 10, 2011 at 06:30 AM
I'm not a hundred percent on this, but since you're spawning objectA directly on top of objectB, it never 'enters' the trigger per se, it just is suddenly in it, so OnTriggerEnter is never called. Trying changing from OnTriggerEnter to OnTriggerStay. If that doesn't work I do not correctly understand your problem.
Thanks for answering Tuck. I had already done that, because like you I had the same thought. I instantiate ObjectA 2 units below ObjectB and have it move very fast 2 units upwards, inside ObjectB. ObjectB's tag does not change to "VacancyTesterFull". When I hit pause and just touch the objectA's translation gizmo, objectB's tag changes to "VacancyTesterFull" (as wanted) and it seems like the engine needs something else to take notice of objectA's position.
Your answer
Follow this Question
Related Questions
Is it possible to convert a Collider into a Spawner? 0 Answers
Which setup should I use for spawning? 0 Answers
Spawning explosions and detecting objects in range 1 Answer
Spawn OnTriggerEnter 0 Answers
Trigger Spawning? 1 Answer