Forum rules - please read before posting.

Modify object which hotspot has been clicked

edited April 2023 in Technical Q&A

Hi,

Is there any way to relay the object which hotspot has been "Use:"d and use this to modify that object?
As an example, if I have 30 buttons (each with a hotspot) that will change color when pressed, instead of making 30 action lists, is there any way to make one action list that would change the color of the object which hotspot was just clicked? This action would then go in all Use: fields of all 30 buttons. In this example the "Change Material, renderer" would be "Render of object which hotspot was clicked". Same could be used for e.g. Object:transforms where Moveable Object would also be "Object which hotspot was clicked" etc.

Comments

  • Yes - ActionList parameters can be used to "recycle" Actions by altering their field values at runtime.

    In your example, a GameObject parameter named "Render object" could be defined, and then used to override the renderer field on the Object: Change material Action.

    A tutorial on parameters can be found here.

    Parameter values can be set in a number of ways, but to do so as part of a Hotspot interaction, use the "Set Interaction Parameters" component. Attach this to your Hotspot, and you can then set values for all parameters your Use interaction has defined.

    A more advanced tutorial that uses this technique to prefab puzzle logic can be found here.

  • Yes!! Thank you for this. Worked great. First time to use the Set Interaction Parameters component!

  • Sorry, one more thing in relation to the above. To continue the above example, when resetting the 30 buttons' material/transform/component variable, is there any way to do this in AC without a foreach-type custom script? All buttons are child objects of the same parent. I currently have a component variable IsPressed on each button to avoid pressing it twice, and a "Reset all buttons"-button. With my limited C# knowledge and how to link a custom script to the action list, the method I'm using now is a 30-step action list to reset each material/transform/comp variable etc.

  • No - a script would be best in this case.

    I can assist, however. To bulk-assign "IsPressed" bool variables to False, you can use this script:

    using UnityEngine;
    using AC;
    
    public class ButtonResetter : MonoBehaviour
    {
    
        public Variables[] variables;
    
        public void Reset ()
        {
            foreach (Variables _variables in variables)
            {
                _variables.GetVariable ("IsPressed").BooleanValue = false;
            }
        }
    
    }
    

    To run it, add to the scene and use the Object: Call event or Object: Send message Action to trigger the component's Reset function.

  • edited April 2023

    Thanks a lot for this. It works fine! I might have got a bit ahead of myself in trying to do more than my skills allow, and this may be more of a C#/unity question but any pointer would be great. The below is to reset Bool "IsIn" to false, and reset position of z for all child objects. I will also add material etc. to this as needed.
    To use the above script in various situations, I tried the following

    public class ResetChildren : MonoBehaviour
    {
    
        public Transform parentObject;
        public string BoolVariableName;
        public bool newBoolVariableValue;
        public float newZPositionValue;
        public float TransitionTime;
    
        public void Reset()
        {
            foreach (Transform child in parentObject)
            {
                Variables variable = child.GetComponent<Variables>();
                variable.GetVariable(BoolVariableName).BooleanValue = newBoolVariableValue;
                Vector3 childPosition = child.localPosition;
                childPosition.z = newZPositionValue;
                child.localPosition = childPosition;
            }
        }
    }
    

    https://imgur.com/a/zWZAMXB

    1. I get one error when running the scene Resolve of invalid GC handle (attached)
    2. The script actually does exactly what I want it to do, except for the error, all variables are reset and all the objects return to their original z-value positions.
    3. I want to add a "Transition time" for the reset z-values, and added this as a script variable but don't know what to do with it. I tried looking at the ActionTransform.cs script to get pointers, but couldn't understand it.
  • I get one error when running the scene Resolve of invalid GC handle (attached)

    This can be safely ignored.

    I want to add a "Transition time" for the reset z-values, and added this as a script variable but don't know what to do with it. I tried looking at the ActionTransform.cs script to get pointers, but couldn't understand it.

    Unity's base Transform component doesn't feature its own "move over time" functions - if you use that, you need to have your script run a coroutine to update them each frame.

    AC's ActionTransform script relies on AC's Moveable component, which does provide these functions. If you attach a Moveable, you can use it to handle this for you by replacing:

    child.localPosition = childPosition;
    

    with:

    child.GetComponent<Moveable> ().Move (childPosition, MoveMethod.Smooth, false, 5f, null);
    

    Replacing "5" with the intended duration.

  • Thanks again!! On a Sunday!!
    It seemed the Move() with 5 arguments needs a Marker in the first slot. I didn't know how to convert the Vector3 childPosition to a Marker so I tried the Move() with 8 arguments

                child.GetComponent<Moveable>().Move(childPosition, MoveMethod.Smooth, false, TransitionTime, TransformType.Translate,false,null,false);
    

    And it works!! Thanks!! The Scripting guide pages are slowly becoming understandable for me!

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.