---
title: GCVirtualController
framework: gamecontroller
role: symbol
role_heading: Class
path: gamecontroller/gcvirtualcontroller
---

# GCVirtualController

A software emulation of a real controller that you configure specifically for your game.

## Declaration

```swift
class GCVirtualController
```

## Mentioned in

Adding virtual controls to games that support game controllers in iOS

## Overview

Overview Use a virtual controller to display software controls that you can customize over your game. You create a virtual controller from a configuration where you choose the input elements to display. You can even customize the images for the elements. When you connect the controller to the device, users interact with it similarly to a real controller.

To add a virtual controller to your game, create a GCVirtualController.Configuration object containing the elements you want to appear in the controller. Then create the virtual controller by passing the configuration to the init(configuration:) method. Use the connect(replyHandler:) method to display the virtual controller on the screen. To customize an element in the virtual controller, pass a new GCVirtualController.ElementConfiguration object for the element to the updateConfiguration(forElement:configuration:) method. You process input from a virtual controller similarly to a real controller. Use the controller property to get the underlying GCController object. You can either poll the elements of the controller object or set the element’s handlers to get callbacks when their input values change.

## Topics

### Creating virtual controllers

- [init(configuration:)](gamecontroller/gcvirtualcontroller/init(configuration:).md)
- [GCVirtualController.Configuration](gamecontroller/gcvirtualcontroller/configuration.md)

### Customizing the elements

- [updateConfiguration(forElement:configuration:)](gamecontroller/gcvirtualcontroller/updateconfiguration(forelement:configuration:).md)
- [GCVirtualController.ElementConfiguration](gamecontroller/gcvirtualcontroller/elementconfiguration.md)

### Accessing the elements

- [controller](gamecontroller/gcvirtualcontroller/controller.md)

### Connecting and displaying virtual controllers

- [connect(replyHandler:)](gamecontroller/gcvirtualcontroller/connect(replyhandler:).md)
- [disconnect()](gamecontroller/gcvirtualcontroller/disconnect().md)

### Presenting a custom interface

- [setPosition(_:forDirectionPadElement:)](gamecontroller/gcvirtualcontroller/setposition(_:fordirectionpadelement:).md)
- [setValue(_:forButtonElement:)](gamecontroller/gcvirtualcontroller/setvalue(_:forbuttonelement:).md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)

## See Also

### Virtual controller

- [Adding virtual controls to games that support game controllers in iOS](gamecontroller/adding-virtual-controls-to-games-that-support-game-controllers-in-ios.md)
