Facepunch / garrysmod-issues

Garry's Mod issue tracker
141 stars 56 forks source link

Entity:GetClass() not recognizing func_button and some others clientside #3667

Open Gmod4phun opened 5 years ago

Gmod4phun commented 5 years ago

Details

The Entity:GetClass() function works nicely clientside for things like func_door etc, but for some reason when used on a func_button, it returns "class C_BaseEntity". This is a slight problem, as you cannot decide whether a not an entity is a button clientside. Why does this happen, I mean, a func_door, func_brush etc is recognized clientside, why a func_button isn't? Also logic_relay seems to be suffering from the same problem. This makes it impossible to draw information of those entities without networking it from the server. Is this something fixable or an engine problem?

image

lubor-slusny commented 5 years ago

logic_relay is serverside entity

Kefta commented 5 years ago

All func_* and logic_* entities are serverside only - they only exist clientside as C_BaseEntitys to render the model. This is done purposefully as the client doesn't need to know the actual entity class or functionality, just that it exists and has a model.

Gmod4phun commented 5 years ago

But as you can see in the picture, func_door, func_movelinear etc get their class returned properly on client (none of the code I ran was serverside). If it works for those, why does not it work for the buttons? And why does it even work for those entities in the first place, that is a mystery for me.

thegrb93 commented 5 years ago

Not all of them are server-side only but most are.

h3xcat commented 5 years ago

Those entities have clientside classes due to required processing on the client. Such as movement prediction, animation, special rendering, etc. If there is no clientside processing required, then the client's engine will just use base class.

Although for buttons, they do have movements. And C_BaseEntity doesn't have any movements.

Gmod4phun commented 5 years ago

That is what is bugging me about it, func_buttons do infact move, same as doors, yet they seem not to be defined on the client. An exact explanation as to why it is so would be nice. Thanks for the answers so far though.

thegrb93 commented 5 years ago

Because valve has optimized netcode as much as they could. Look in the sourcesdk code and see for yourself.

Kefta commented 5 years ago

So it seems entities with a sendtable will have their name networked, but entities without it will default to the class name of the entity that last declared a sendtable in the inheritance chain. In most cases, this is CBaseEntity. This is why func_door works but func_button doesn't.