Ray cast sender is nil (SOLVED)

Hi there,

It is not clear in the documentation: If a ray cast is sent from 2 different objects who will receive the hit message? Because it seems to me that a ray casting from one object is being detected by another object.

Also, the sender value is nil.

I did some tests, it seems now the issue is related to the visibility of the method that is handling the event, for example in my code:

local function on_push_hit(self, message)
	pprint(go.get_id())
end

local function on_push_missed(self, message)
	pprint(go.get_id())
end

it will print the game object correctly, however if it is not local, then it will receive ray cast events from all objects that are ray casting.

yeah, after digging a little further I found what was wrong, after reading https://www.defold.com/manuals/lua/#_lua_contexts_in_defold I could understand what I was doing wrongly.

Yes, this is a perfect example of the kind of problems you may run into with global functions. You should use local functions at all times to avoid this and similar problems.

1 Like