Forum rules - please read before posting.

ActionList in prefab problem

Hi!
I need to put door into prefab and create many doors on my level.
Door by clicking on it should open.

I put hotspot and created interaction script. But after instantiating of prefab I found that content of action list (interaction) is not stored in prefab at all.

I`ve tryied to use ActionList asset. But problem that I can`t transfer parameter to it with gameobject which should be rotated (link to movable part of the door). Parameters just ignored because it`s ActionList asset it is looking for link in whole scene even if I fill parameters from custom script which I`ve made for this prefab. Any ideas how can I do this stupid door? =)

Comments

  • Code of my script to setup action list parameters (maybe I am doing something wrong?)

    [RequireComponent(typeof(ActionList))]
    public class SetActionListParams : MonoBehaviour
    {
        public GameObject[] objectsToLink = new GameObject[0];

        void Start()
        {
            var cmp = GetComponent<ActionList>();
            if (objectsToLink.Length <= cmp.parameters.Count)
                for (var i = 0; i < objectsToLink.Length; i++)
                    cmp.parameters[i].gameObject = objectsToLink[i];
        }
    }

  • Indeed - the fact that ActionLists cannot exist as prefabs is the reason that ActionList Assets exist.  Are you still working with Assets?  Your script suggests you're back to using ActionLists.

    I'm assuming you've made sure that the parameter indices match up with the objectsToLink.  Also know that if you want to assign GameObject parameters to an ActionList Asset, you need to add a ConstantID component to the GameObject and assign the ID number instead - this is how ActionListAssets keep track of GameObjects that exist in a scene.

    If you're assigning the parameters to an ActionList / ActionListAsset before it's run, it may be that they're resetting once you run it.  If you get the newly-released AC v1.51, the ActionList: Run Action makes the assigning of parameters optional - so try unchecking that if you're assigning parameters manually.

    Also note that if you can run the posted code once an ActionList has begun, however, there should be no problem.
  • edited March 2016
    >Your script suggests you're back to using ActionLists.
    Nope. I am attaching this script to a trigger/hotspot object (if mean RequireComponent attribute). Indices are matching but in case of Trigger script sending collider object as 0 parameter.

    >ConstantID
    this is what I`ve missed, also tried that - not helped.

    PS. for future maybe you should make this prefab workflow more user friendly =)
  • found problem in ActionList.cs

    // Wrong part in Awake method:
    parameters = assetFile.parameters;

    // Should be
    parameters = assetFile.parameters.Select(p => new ActionParameter(p)).ToList();

    Because in first case all parameters are used directly from prefab and (if you have N>1 instances of this prefab) last assigned intValue will be used.
  • edited March 2016
    This is how my solution of this problem looks now, maybe I am doing something wrong =)
    It works but it`s cumbersome =(


    [RequireComponent(typeof(ActionList))]public class SetActionListParams : MonoBehaviour
    {
        public ConstantID[] objectsToLink = new ConstantID[0];

        void Start()
        {
            var cmp = GetComponent<ActionList>();
            if (objectsToLink.Length <= cmp.parameters.Count)
                for (var i = 0; i < objectsToLink.Length; i++)
                    cmp.parameters[i].intValue = objectsToLink[i].constantID;
        }
    }
  • edited March 2016
    Another question as far as we are talking about doors =) 
    how can I switch hotspot walk-to marker, depending on what side of the door player is tanding?

    e.g. I have two markers (from both sides of the door) and player will go to nearest one.
    another possible solution is to move marker to nearest to player position in some radius from door.
  • Triggers are a subclass of ActionLists - I was only getting at whether it was a scene-based ActionList vs an ActionListAsset file.

    Thank you for pointing out the issue in Awake(), I will look into that.

    With v1.51, you can create an event listener for when a Hotspot is interacted with.  Specifically, you want the OnHotspotInteract event.  With this, you could write a script attached to your Hotspot that looks at two Markers, the Hotspot, and the Player, to determine which Marker the player should move to (and assign it as the Hotspot's Walk to Marker manually).
  • WRT to the Awake() change, I believe this should be optional - as changing it will affect existing game logic.  Likely in the form of a "Sync parameter values?" toggle in the ActionList's properties - then, using the ActionList: Set parameter Action on the ActionList will either affect just the ActionList's parameters, or the linked Asset file plus all linked ActionLists.
  • edited March 2016
    >changing it will affect existing game logic
    sure, maybe someone using it a lot will say thank you for backwad compatability =)
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.