This isn't a support request per se. I noticed recently that Chat GPT knows Unity code incredibly well. Yesterday, I was making a complex UI script and I asked it very specific pointed questions and it was able to give me perfect code with advance coding patterns that were a revelation to me. I simply had to copy and paste it and it worked perfectly.
Then today, on a whim, I asked it a simple question:
"The game I'm making in Unity uses the Adventure Creator addon. In a script I'm writing, I want to reference an Adventure Creator interaction and call it programmatically when the Esc key is pressed. "
This was its response:
To call an Adventure Creator interaction programmatically when the Esc key is pressed, you'll need to use Adventure Creator's scripting API. Adventure Creator is a powerful toolkit for making point-and-click adventure games in Unity, and it provides a comprehensive API for interacting with its systems through code.
Here's a basic example of how you can achieve this. Note that this approach requires a basic understanding of how Adventure Creator manages its interactions and assumes you have an interaction you wish to call:
Reference Adventure Creator's Namespace: To access Adventure Creator's classes and methods, you need to include its namespace at the top of your script.
using AC; // Adventure Creator namespace
Script Setup: You'll write a script that listens for the Esc key press and then calls the desired interaction. Adventure Creator uses "ActionLists" to define interactions, so you'll be calling an ActionList programmatically.
Here is an example script that does just that:
using UnityEngine;
using AC; // Adventure Creator namespace
public class CallInteractionOnKeyPress : MonoBehaviour
{
public ActionListAsset interactionToCall; // Assign this in the Unity Editor
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
// Check if the interactionToCall is not null
if (interactionToCall != null)
{
// Kick off the interaction (ActionListAsset)
AdvGame.RunActionListAsset(interactionToCall);
}
}
}
}
In this script:
ActionListAsset interactionToCall: You need to assign this variable in the Unity Editor. Drag and drop the ActionList asset you want to run when Esc is pressed.
AdvGame.RunActionListAsset(interactionToCall): This line is responsible for executing the specified ActionList.
Assign the ActionListAsset: In the Unity Editor, attach this script to a GameObject (it could be an empty GameObject dedicated to handling this script). Then, in the Inspector, drag your desired ActionListAsset into the Interaction To Call field of the script component.
Now, whenever you press the Esc key while the game is running, it should trigger the specified Adventure Creator interaction.
Remember, the actual implementation details might vary depending on the version of Adventure Creator you are using and the specific requirements of your project. Always refer to the official Adventure Creator documentation for the most accurate and detailed information.
Granted this is a simple example, but I was pleased and a little shocked, too. I've been throwing even more complex questions at it and it seems to be able to give me perfectly baked code instantly along with detailed explanations on how to use that code and caveats.
I apologize if this is old news to everyone here, but to me this was a revelation. Anyway, just putting it out here in case this helps someone.
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
I further went on to ask:
"in the above adventure creator code, what if I want to run an AC interaction that is in the scene (and not an asset)"
Here was its response:
Certainly impressive - though it's my understanding that ChatGPT's data isn't "live", so it won't be able to suggest up-to-date techniques and code API.
To have an ActionList asset run when a given input is pressed, you define an "Active Input" in the top toolbar's Active Inputs window - no need for custom scripting.
Thanks for pointing that out, Richard. I actually went back to ChatGPT with your feedback and wrote to it:
And this was it's response
I guess it heavily relies on the prompt direction, but I've been using it heavily for both AC and Unity code now, (I have the paid version, which runs on GPT 4, which is updated to last year I believe.) I'm pretty sure it has it's limitations, but for now, it beats googling answers, and perhaps once they figure out the 'live' data issue, it'll replace search engines.