- Home /
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: http://docs.unity3d.com/Documentation/ScriptReference/VersionControl.Provider.html
Almost every one of these returns a Task: http://docs.unity3d.com/Documentation/ScriptReference/VersionControl.Task.html
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?
Answer by dbarth · May 15, 2014 at 06:19 AM
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);
Thanks for leaving this here! It was very helpful to me and fixed my problem - evidently the same one!
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Camera rotate and move follow Player 1 Answer
Microsoft Visual C# Compiler error 0 Answers
How to use a boolean to control another object boolean using C# script 4 Answers