pub struct Class { /* private fields */ }Expand description
Entity class definition.
Represents the type and structure of an entity. Classes define:
- Class ID: Numeric identifier
- Class name: Human-readable type name (e.g., “CDOTA_Unit_Hero_Axe”)
- Serializer: Defines which properties exist and how they’re encoded
§Class Name Patterns
Entity class names follow patterns that help identify their type:
CDOTA_Unit_Hero_*- Dota 2 heroesCDOTA_Unit_*- Dota 2 NPCs and unitsCDOTA_Item_*- Dota 2 item holdersCDOTA_*- Other Dota 2 entitiesCCitadelPlayerPawn- Deadlock playersCPlayer_*- CS2 players
§Examples
§Using class information
use source2_demo::prelude::*;
let class = entity.class();
println!("Entity ID: {}", class.id());
println!("Entity name: {}", class.name());
// Check entity type
if class.name().starts_with("CDOTA_Unit_Hero_") {
println!("This is a hero!");
}§Finding all entities of a class type
use source2_demo::prelude::*;
// Find all heroes
let heroes: Vec<&Entity> = ctx.entities()
.iter()
.filter(|e| e.class().name().starts_with("CDOTA_Unit_Hero_"))
.collect();Implementations§
Source§impl Class
impl Class
Sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
Returns the human-readable name of this class.
Examples: “CDOTA_Unit_Hero_Axe”, “CDOTA_PlayerResource”
§Examples
use source2_demo::prelude::*;
match class.name() {
"CDOTA_PlayerResource" => println!("Found player resource"),
name if name.starts_with("CDOTA_Unit_Hero_") => println!("Found hero"),
_ => println!("Other entity type"),
}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Class
impl !RefUnwindSafe for Class
impl !Send for Class
impl !Sync for Class
impl Unpin for Class
impl UnsafeUnpin for Class
impl !UnwindSafe for Class
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more