Unity – Universal Render Pipeline and Input System

The Unity URP (Universal Render Pipeline) contains a new Input System[5].

This is configured slightly differently.

Add some objects to your scene.

Apply a Rigidbody to the player object (in this case[6] the sphere)

Go to Window > Package Manager

Open the package manager and select Unity Registry to see all of the options.

Search for Input System and then install

You might get a warning message, if you do select Restart

In the Inspector select Add Component[1] and then add the Player Input component[1]

Player input is not yet configured.

Click the Create Actions… button to set up default inputs[7]

You will be asked where you want to save the input actions config file.

Make sure you save this in a logical place like an Inputs[7] folder.

Drag the input actions file to the Component

We now have the input system[5] attached to the player object.

If we run the program the object won’t move as we haven’t added code to do this yet.

Create a new C# script called PlayerController

Drag the script onto the player object

Double click the script to open it in the code editor

Add the InputSystem to the player controller

Create the variables[2] for the speed of the object, the Rigidbody (to handle physics movement) and the x and y movement.

In the start method assign the Rigidbody to the rb variable[3].

Add the OnMove function[4]. This functions detects user input and we then get the x and y movement and stores this as a 2D vector. We then assign the x and y values to the variables we created earlier.

Now we need[8] to add the code to update the object.

Here we are using the Update() function. This will run once per frame. If you want it to update on a fixed time use FixedUpdate() instead.

As we are using a 3D game we need to convert the 2D vector into a 3D vector. Note here we have change the y value to be on the z (depth) axis.

We then use the AddForce function of the Rigidbody to move the object by the vector multiplied by the speed.

Save the script

Switch[9] back to Unity

You can now see the public variables

Set the speed to a value you want

You now have a working input system

The Unity Roll A Ball tutorial works through this process in a clear project[10].

Terms definitions
1. Component. The three strands of Technology in the NZC (Technological Practice, Technological Knowledge, and Nature of Technology) – together with the six specialist knowledge and skills strands for levels 6, 7, and 8) – support the development of students’ technological literacy. Each of these strands is broken down into smaller groupings (or substrands) called “components”. For […]
2. variables. “Containers” used to label and store data in memory. The data can then be used throughout a program: * Integer variables use only numbers and so can be used for calculations * String variables are sequences of code that may contain numbers, letters, and other characters, and so cannot be used for calculations.
3. variable. A placeholder for a piece of information that can change.
4. function. A named section of a computer program that performs a specific task. Functions help make code more efficient and reusable. They may take input parameters and produce output.
5. System. A set of interconnected parts designed to transform, store, transport or control materials, energy and/or information.
, ,