UnityEditor.VersionControl and Perforce, tasks always fail?

Hi guys,

I’m trying to write a tool that our artists can use to verify their checkins. We’ve had a lot of problems with people adding prefabs but forgetting various dependencies.

We are using Perforce (2014 February 25 visual client) with Unity 4.3.4f1, Pro version with Team license, Windows 7 x64. Perforce Plugin turned on and set up in Project Settings > Editor.

I’m trying to use the UnityEditor.VersionControl.Provider functions found here:

Almost every one of these returns a Task:

Which has a “success” variable.

I am first checking whether the provider is ready and enabled using:

bool providerEnabled = Provider.enabled && Provider.isActive;

Which returns True. However, ALL my actions I attempt return a Task with a failed success state. I have not been able to get information about my ChangeSets, for example.

I have been able to checkout files from code, like this:

if (providerEnabled) Provider.Checkout(targetPrefab, CheckoutMode.Both);

Which works… but the Task returned for that operation says it failed! The files do successfuly get checked out in my Default changelist. I am unable to add/move files around to specific changelists though because Provider.ChangeSets and Provider.ChangeSetStatus() never return anything but a failed Task.

Does anyone know what’s going on? Could it be that Unity and the P4V client became incompatible at some point?

I’ve figured it out and will leave the answer here in case anyone else runs into this issue.

After every action that returns a task, you need to use Task.Wait() before performing another action. Otherwise, I’m assuming you’re attempting Perforce actions too quickly and the first one will generally succeed while the rest will be denied.

Example:

`
// Check out a file

Task checkoutTask = Provider.Checkout(Selection.activeObject, CheckoutMode.Both);

checkoutTask.Wait();

// Query changelist for status (returns a Task containing an asset list)

Task statusTask = Provider.ChangeSetStatus(“49971”);

statusTask.Wait();

// Should both print “True”

Debug.Log("Checkout success: " + checkoutTask.success);

Debug.Log("Changelist status success: " + statusTask.success);
`

OMFG thank you for pointing out the Wait function