Interactable placed on a Character

Shadowing

Member
So I'm making a Interactable where I walk up and talk to a NPC

The 2nd Debug.Log comes up null.
The First Debug is pointing not to the gameObject my Interactable is on. Which is why its null.
Looks like it grabs the first GameObject it finds a collider attached too. In this case CapsuleCollider for the character

So idk Is this attended behavior? Shouldn't it use the collider of the InteractableTarget?
Interactable doesn't even require a collider anymore does it?

Code:
             Debug.Log(obj.name);
             Debug.Log(obj.GetCachedComponent<Interactable>());
            // The object must have the Interactable component.
            if ((m_Interactable = obj.GetCachedComponent<Interactable>()) != null) {



Here is the entire method of my ability in case you don't understand where im referring too

Code:
        protected override bool ValidateObject(GameObject obj, bool fromTrigger)
        {
            if (!base.ValidateObject(obj, fromTrigger)) {
                return false;
            }

            if (m_Interactable != null) {
                return obj == m_Interactable.gameObject;
            }
             Debug.Log(obj.name);
             Debug.Log(obj.GetCachedComponent<Interactable>());
            // The object must have the Interactable component.
            if ((m_Interactable = obj.GetCachedComponent<Interactable>()) != null) {

                // If the ID is used then the IDs must match.
                if (m_InteractableID != -1 && m_Interactable.ID != m_InteractableID) {
                    m_Interactable = null;
                    return false;
                }

                return true;
            }
            return false;
        }
 
This is at the validation stage so it is still trying to determine if the object is valid. It'll find any object specified by the ID or LayerMask, depending on what you are using.
 
Alright so this is probably a bug then.

I have AbilityStartLocation, Interactable and NonAnimatedInteractable which has the IInteractableTarget on it. Its on the most parent game Object.
I have that game Object as the Target for Interactable

When I run my character up to that NPC. The game Object it detects is the CapsuleCollider GameObject created by UCC on character creation.
Code:
Debug.Log(obj.name); // returns CapsuleCollider

This is null cause no Interactable detected. which is correct
Code:
Debug.Log(obj.GetCachedComponent<Interactable>()); // returns null

Steps to reproduce.
  • Add a AI character to your Interactable room in the demo
  • Set up interaction components on it.
It won't work.
Its all because characters don't have colliders on its parent game Object. It seeks out for the first gameObject that has a collider on it.
So it is detecting the interaction but its not choosing the right gameObject that Interactable is added too.


 
Instead of using GetCachedComponent you should use GetCachedParentComponent.
 
Here is a fast way to test it. I just tested this.
On the interact room.


Remove the collider on the chest
Create a child game Object on InteractChest
Add new collider to it.

Go test the interaction is broke
 
I tried GetCachedParentComponent. It didn't work. Cause of the Chest Test I did im certain its a bug and is some how related to colliders.
 
Last edited:
For a temp solution until this gets fixed I'm doing this to fix my problem
Code:
obj.transform.parent.parent.gameObject.GetCachedComponent<Interactable>())

But this causes another issue. The image and message will blink as shown in the videos below. My guess its all from the source issue of obj being the wrong GameObject returned. Because it doesn't it in the demo on the chest if I leave the collider on its most parent gameObject.
But If i move the chest collider in two childs deep just like it is on a character. The demo will react the same with blinking.


Duplicated in the Demo
 
Oops, I thought that I had posted the fix. You can fix this by changing the following within Interact.ValidateObject:

Code:
            if (m_Interactable != null) {
                return obj == m_Interactable.gameObject;
            }
to:
Code:
            if (m_Interactable != null) {
                return obj == m_Interactable.gameObject || obj.transform.IsChildOf(m_Interactable.transform);
            }
 
Ahh ok thanks man that fixed it.

Isn't obj still returning the incorrect gameObject though?
Shouldn't it look for the gameObject with the Interactable on it?
 
I understand whats going on now. CharacterCast is casting between the character and hitting the first collider it hits on the interactable.
Which is why a collider has to exist.

Im using Cast type Trigger for my teleporter since it has no collider.
CharacterCast is a better option when creating triggers by script since I don't have to worry about size of the trigger.
 
Top