Forum rules - please read before posting.

Scene-dependent inventory interaction

I have a "walkie talkie" inventory item which is supposed to initiate a conversation when used from the inventory. The conversation options should be dependent on the active scene, they should be stored in the scene rather than in the assets, and they should be enabled/disabled based on the players progress in the scene.

Is that possible? How would I go about it? Obviously this item needs to work on any scene and I can't wrap my head around how to get the control flow back from the ActionList asset into the currently active scene.

Thanks!

Comments

  • I found a possible way but I doubt it's the most elegant solution:

    I created a custom action "ActionRunSceneInteractionByName" which takes the name of an Interaction existing in the scene and then triggers it:


    public class ActionRunSceneInteractionByName : Action { public override ActionCategory Category { get { return ActionCategory.ActionList; }} public override string Title { get { return "Run scene Interaction by name"; }} public override string Description { get { return "Runs a scene Interaction by name."; }} public string objectName; public override float Run () { // null checks omitted for brevity GameObject gameObject = GameObject.Find(objectName); Interaction interaction = gameObject.GetComponent<Interaction>(); interaction.Interact(); return 0f; } ... public override void ShowGUI () { objectName = EditorGUILayout.TextField ("Object name:", objectName); } ... }

    This action is triggered from the Action List asset configured as a standard interaction.

    This would work in any scene where an Interaction with the configured name exists.

    Any thoughts on this approach?

  • You're on the right track - to run a scene-based Interaction from an ActionList, you'll need to use a shared identifier that can be used to track it in each scene. You needn't rely on a custom Action for this, however, as AC's own Constant ID system can also be used as such an identifier.

    The ActionList: Run Action can be used to run an Interaction from an ActionList asset - once assigned, you should find that AC automatically generates and assigns a Constant ID value for it in both the Action and on the Interaction's GameObject.

    At runtime, this Action will then look for this ID value in the scene. So, if you have a different scene open, you can attach the same ID to a different Interaction to have it be run instead. A Constant ID component's Set field can be set to Manual to assign a specific ID value.

    A pair of tutorials covering this topic can be found here.

  • edited July 2022

    Thanks, Chris. Now the PROTIP on page 218 makes sense. It's always abstract information until you encounter an actual use case 😂

    I would like to make a suggestion. It doesn't fit to the topic of this conversation, but it's very much related. I am using the "follow cursor" option for my game camera and when the player uses the walkie talkie I use the Character / Hold object action to grab the transmitter before I trigger the conversation.

    Unfortunately, as the player moved the mouse to the top left inventory item and the camera is frozen due to the unticked "Follow during cutscenes?" option, they typically don't see this animation.

    I wanted to have an option to center the camera back on the target during cutscenes so that the player can actually see what the character does on screen regardless of the current mouse position and the scale of the follow mouse effect. I simply enhanced CursorInfluenceCamera.CreateRotationOffset for that purpose and changed the offset back to the center with double speed:

    if (followCursor)
    {
        if (KickStarter.stateHandler.IsInGameplay () || (cursorInfluenceDuringCutscenes && KickStarter.stateHandler.IsInCutscene ()))
        {
            // standard follow cursor functionality omitted
        }
        // added this:
        else
        {
            Vector2 targetCursorOffset = new Vector2 (0.5f, 0.5f);
            actualCursorOffset = Vector2.Lerp (actualCursorOffset, targetCursorOffset, Time.deltaTime * followCursorSpeed * 2f);
        }
    }
    

    Maybe it makes sense to add an option for that, "Return to camera target during cutscenes" or similar, so that this functionality would be available out of the box?

    Thanks for considering this!

  • Yes, good suggestion - I'll give it some consideration.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.