Update.
It's working now, I use world:pick to raycast and test if the pickinfo I got is the object I want to show.
Since the raycast wont work with hidden objects, I am changing its materials.
Now the catch is, How can I detect if my raycast is not hitting the object I got before, so I can put the original material back?
Tried this but my lastValidPickinfo thing is not working:
if self.entity.world:Pick(p0,p1, pickinfo, 0, true) then
if pickinfo ~= nil then
if pickinfo.entity ~= nil and pickinfo.entity:GetKeyValue("name") ~= "" then
self.lastValidPickinfo = pickinfo
pickinfo.entity.script.showObject = true
if self.lastValidPickinfo.entity:GetKeyValue("name") == "" then
self.lastValidPickinfo.entity.script.showObject = false
end
end
end