Quick tips for writing your own wrapper
masterWhen implementing a custom wrapper, follow these implementation guidelines to ensure it integrates correctly with the Gym ecosystem:
- Initialization: If you override the
__init__function, you must callsuper(class_name, self).__init__(env)to properly initialize the wrapper. - Accessing Layers:
- Use
self.envto access the immediate previous layer in the wrapper chain. - Use
self.unwrappedto access the base, original environment (bypassing all wrappers).
- Use
- Attribute Inheritance: The following attributes are automatically copied from the previous layer to
self:metadataaction_spaceobservation_spacereward_rangespec
- Method Overriding: To have an effect, your wrapper should override at least one of the following methods:
__init__(self, env),step,reset,render,close, orseed. - Data Flow: Your overridden methods should typically take inputs from the previous layer (
self.env) or the inner environment (self.unwrapped).