Forum Discussion

jcraig358's avatar
jcraig358
MHCP Partner
9 months ago

entity.getComponents() not working

Hi 🙂
I'm having an issue where the local implementation of the entity.getComponents() function only finds the requested components on objects that a player has previously owned (grabbed).

The situation is set up such that there is an object (bat) that will hit a collider assigned to a player. Player1 picks up the bat (ownership is transferred) and hits Player2's collider (which is owned by Player2). Running batEntity.getComponents(batScript) function within Player2's collider does not find a batScript component on the bat. Even if P1 drops the bat and grabs it again, I get the same result.

However, after P1 drops the bat and P2 picks up the bat and hits P1, then getComponents() finds the requested component. Subsequently, if P2 drops the bat and P1 picks it up and hits P2, now getComponents() finds the batScript component as well. Thus, getComponents() seems to only find components on entities that the player has owned/grabbed previously.

An alternative scenario is if P1 hits a sever NPC with the collider, the server's getComponents() finds the batScript.

To note, the script for the bat and the script for the collider are set to run locally because PlayerControls are required for those scripts.

From this, it seems that P2 is not loading batScript on their local version of the batEntity until it becomes relevant to them (when they grab it and own it). Once they do, they load the script on to bat, are able to now recognize it and can find it with getComponents().

Is there a way to force the loading of the local script before owning it so that it can be found?

No RepliesBe the first to reply