Forum rules - please read before posting.

Inventory element show

Hi well, I have a problem with some stuff for a long time. I want something like take an object and shows in the inventory and then activate a small animation.

Now I have this: https://drive.google.com/open?id=1QSWDu_6SoSZTkVxb2hu99MxDySdPmWvJ

Every inventory object has the button an animation like you see in the video when you are hover(highlighted).
I want that animation play on the inventory object when you pick up and show the inventory bar.
What I want showing an example it´s:https://www.youtube.com/watch?v=03Wt5URuKwY (min 2:50 take a cactus and show in the inventory and the animation in the inventory object)

I know I can do something with the custom action script but im a little bit lost with this especially. 

Thanks  

 

Comments

  • The example video you provided does the following:

    -Adds the item to the inventory
    -Transition the menu in
    -Animate the item
    -Transition the menu out

    The menu transitions in AC can be done with the Menu: Change state Action, provided that the Menu in question has animated transitions configured.

    The Object: Highlight Action can be used to show a given Inventory item's Highlighted texture graphic.

    To have such a sequence of Actions run each time an item is picked up, you'd want to look into using ActionList parameters, so that you can create a generic "Add an item and show it" ActionList - and then run it while setting the value of the Item to add/show each time you do so with ActionList: Run.

    For something more complex that the simple "highlight on/off" effect, you can manipulate the UI Button/Image component directly if the Menu is rendered with Unity UI.

    The following code can be used to access the "UI Button" in an Inventory menu that is associated with a given inventory item:

    AC.MenuInventoryBox inventoryBox = AC.PlayerMenus.GetElementWithName ("MyInventoryMenu", "MyInventoryElement") as AC.MenuInventoryBox;
    UnityEngine.UI.Button uiButton = inventoryBox.GetUIButtonWithItem (invItemID);

    Where "MyInventoryMenu" is the name of your Menu, "MyInventoryElement" is the name of your InventoryBox element (both as set within the Menu Manager), and invItemID is the ID number of the associated inventory item.  This can be parameterised in the same way as the steps above within a cutsom Action:

    https://adventurecreator.org/tutorials/getting-custom-action-work-parameters

  • Well, Chris works fine in one scene, then when I change the scene doesn't work.
     
    here is the code:

    public class ActionInvAnim : Action
    {

            // Declare variables here
           
            public GameObject objectToAffect;
            public int constantID;
            public int parameterID = -1;
            public int invID;
            public Animator anim;

            public ActionInvAnim()
    {
    this.isDisplayed = true;
    category = ActionCategory.Inventory;
    title = "InventoryAnimationPickUp";
    description = "Esto sucede cuando se agarra un objeto y muestra la animacion cuando se agarra";
    }
    override public float Run ()
    {
                 MenuInventoryBox inventoryBox = AC.PlayerMenus.GetElementWithName("Inventory", "InventoryBox") as MenuInventoryBox;
                 UnityEngine.UI.Button uiButton = inventoryBox.GetUIButtonWithItem(invID);
                 anim = uiButton.GetComponent<Animator>();
                 anim.SetTrigger("pick");
              

                if (!isRunning)
    {
    isRunning = true;
    return defaultPauseTime;
    }
    else
    {
    isRunning = false;
    return 0f;
    }
    }


    #if UNITY_EDITOR

            override public void ShowGUI(List<ActionParameter> parameters)
            {

                parameterID = Action.ChooseParameterGUI
                ("GameObject to affect:", parameters, parameterID, ParameterType.InventoryItem);

                if (parameterID >= 0)
                {
                    constantID = 0;
                    objectToAffect = null;
                }
                else
                {
                    objectToAffect = (GameObject)EditorGUILayout.ObjectField
                         ("GameObject to affect:", objectToAffect, typeof(GameObject), true);

                    constantID = FieldToID(objectToAffect, constantID);
                    objectToAffect = IDToField(objectToAffect, constantID, true);
                }


            }

            override public void AssignValues(List<ActionParameter> parameters)
            {
                invID = AssignInvItemID(parameters, parameterID, invID);
            } 
  • When posting scripts, please post them in full - and ideally formatted via eg. pasteall.org.

    I can't debug your code since it relies on your own menu and UI prefab to work.  Try placing in Debug.Log statements within your Run() function to see which variables are assigned vs which aren't.

    Also the whole "if (!isRunning) / else" block can be replaced with "return 0f;".  Please see the comments in the ActionTemplate.cs script for this function.
  • Hi Chris Here is the code:http://pasteall.org/913056
    The problem i think it´s in the animator.
    here is the debug.log console:
    https://drive.google.com/open?id=1ldDXHw1JpjJWcgPJarZkF5fcsyCHs2JS

  • Indeed - the AC side of things looks fine.

    As it's warning you about this, have you assigned an Animator Controller to your Animator component?
  • Yes, the problem I think its that its place on the prefab component of the inventory. (my inventory is the same template of ac)
  • As it should be.  Or do you mean that the "uiButton" variable in your script is referencing the original prefab asset file, rather than the runtime scene instance of it?
  • yes i think thats the problem, any idea to solve that? 
  • My own tests don't have that behaviour - it works fine for me.  The code in your ShowGUI method, however, is irrelevant since "objectToAffect" is never used in the Run method.

    Are you sure that's what it is?  Try logging the animator's scene:

    Debug.Log (uiButton.gameObject.scene.name);
  • It´s not that problem here is the log
    https://drive.google.com/open?id=1PijnvcpivPaIiv-1KDtq5lkAD44UBss-

    All the buttons have the same animator controller 
    https://drive.google.com/open?id=13w3Wq7ADDx6mBfMV2JjWD0zibsVRE7WE

    The controller has a trigger called "pick" 
    https://drive.google.com/open?id=1QM6OSVcRPzs37vvy5GkO67DIEmIRLVMa

    The inventory (the gameobject(x) it´s because all the inventory object has a small graphic container)
    https://drive.google.com/open?id=114EGTi-1Qg8wcXQ449w1fsAfEhR_xxK9

    An the inventory menu
    https://drive.google.com/open?id=1Je_eaHJq6gFgAwY--05mp5U5J2vFQpoh 

    I was confused about the instance because i search if anybody has the same error but only found that but it wasnt.

    The problem is when i take more than one object i found it now.

  • This is likely a Unity bug, as the Animator's Controller is becoming unset at runtime.

    Try assigning the Animator's Controller when the Action runs:
    http://pasteall.org/919015/csharp

  • Well, it´s not that the solution. It happens only apply to one object every time i pick up the same inventory object play the animation. it´s like the parameters are not working now. change some stuff to parameter the invId int but happens the same old problem. I check and the animator is assigned well. So it´s a bug or not it´s really a complication.
    Animator is not playing an AnimatorController 
    UnityEngine.Animator:SetTrigger(String) 

  • Well, i found it and solve it!!! 
    It was a timing problem i just add anim.gameObject.SetActive(true); after   anim.runtimeAnimatorController = runtimeAnimatorController; and works fine!!
    Thanks again
  • :( was a false alarm, it works fine on the editor but when I made a build all crashes with the inventory.
  • The line error is this Animator anim = uiButton.GetComponent<Animator>();
    NullReferenceException: Object reference not set to an instance of an object

  • So that error only shows up in Builds?

    If that's the case, then inventoryBox is being correctly assigned, so the issue lies with assigning uiButton:

    UnityEngine.UI.Button uiButton = inventoryBox.GetUIButtonWithItem(invID);

    This requires the chosen item (invID) to be in the player's inventory at the time that it's run.  You can try debugging further by placing more Debug.Log statements within the MenuInventoryBox script's GetUIButtonWithItem method.

    This may even be an issue unique to your project - as it's not a bug I experience at all.
  • I got it!

    The problem was that this lines of code:
    override public void AssignValues(List<ActionParameter> parameters)
            {
                invID = AssignInvItemID(parameters, parameterID, invID);
            }

    where assigned in the wrong place. It was placed if unity_editor... I sent it out of that if and put it at the and beginning work fine in the editor and build!!! 

    Thanks, Chris again 
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.