codeAPI Reference
s&box BaseCarryable.IEvent: World model events
BaseCarryable.IEvent Interface API Reference
BaseCarryable.IEvent is an interface for receiving world model lifecycle events on carryable objects (weapons, items). Implement this on components within a carryable's world model prefab to be notified when the world model is created or destroyed.
Type Signature
CSHARP
public partial class BaseCarryable : Component
{
public interface IEvent : ISceneEvent<IEvent>
{
public void OnCreateWorldModel();
public void OnDestroyWorldModel();
}
}Methods
OnCreateWorldModel()
Called when the world model is created and attached to the holder (player or NPC). Use this to initialize components that depend on being attached.OnDestroyWorldModel()
Called when the world model is destroyed (when the item is dropped or the holder changes). Use this to clean up resources.Usage
CSHARP
// In a component within the world model prefab
public class MyWeaponEffect : Component, BaseCarryable.IEvent
{
void BaseCarryable.IEvent.OnCreateWorldModel()
{
// Initialize effects when attached to player
StartParticleEffect();
}
void BaseCarryable.IEvent.OnDestroyWorldModel()
{
// Clean up when dropped
StopParticleEffect();
}
}Notes
- Implements ISceneEvent for event broadcasting within the GameObject hierarchy
- Events are posted to the world model GameObject
- World model is created when item is picked up/held
- World model is destroyed when item is dropped
- Used for weapon-specific effects that depend on attachment state
- World model is marked NotSaved and NotNetworked
Was this helpful?