Forum rules - please read before posting.

Spawned objects: Inventory updates but item not deleted from scene the proper way

edited June 2017 in Technical Q&A
Hi,

I'm new to AC, I've got a confusing issue with using cloned gameobjects with hotspots and I hope I can please get some help. This first image hopefully gives an idea of what the issue is. I've got a gameobject prefab with a corresponding hotspot prefab being spawned to 4 locations on start by a script outside of AC (AC calls that script on start). I set up the prefab (called Access Card) to work with the Hotspot prefab (called Access Card Hotspot) such that the Access Card action list is not activated directly but through an ItemPickup action list which runs the Access Card action list when the hotspot is clicked, by setting parameters previously allowed on the Access Card action list. I did this following advice given elsewhere on the forum as this being the way to go when trying to spawn hotspots. It works after a fashion, the item and it's hotspot gets spawned to the four different spawn points and the inventory is updated with a new item each time the hotspot is clicked, the only problem is that the item and hotspot do not disappear from the scene at each hotspot after being clicked, until the full cycle of four clicks is completed at the same hotspot (which is not what is intended, each hotspot should be deactivated after it is clicked and added to inventory and player should have to travel to the next hotspot to collect that as well as an inventory item). It is even more confusing because the cloned hotspots in the scene disappear in sequence upon each click, but in game view, while they do disappear at the corresponding spawn location if player travels there to check it out, they remain at the original location that was being clicked, until the last one is clicked. This is a bit confusing to explain but I made a video which I hope would help, I refrained from speaking till this point to avoid confusion but you can start at the beginning to see how I set up the hotspot and action lists. The images below might also help in explaining my set up: 

image
image
image
image
image
image
image

p.s. I am using Unity 5.6.0f3 and Adventure Creator 1.56g
Thanks in advance for any help!

Comments

  • Ummm... AC in essence doesn't like duplicated objects very much. Your issue is most likely due to the fact you are using the same constant ID in your actions and objects.

    Anyway, AC gathers references to all AC related objects when a scene starts (or when you use the add or remove Action), and uses the constant IDs to identify objects which need to be referenced by Actions...

    So, If your actions are referencing a specific Constant ID, then they will affect the first object in the list found with that ID, that probably explains why the actions keep referencing the next object with the same ID (if you are destroying one, then the action will naturally go to the next object in the list with the same ID). 

    What I've done in my projects is to run actions which don't need to reference the object itself in regular hotspots. But use some scripting for those behaviors which need to reference a particular instance (like item disabling/destruction).
  • Welcome to the community, @DADA_universe.  I took a few notes as I was watching the video:

    The AccessCard ActionList is confusing to me because you appear to be removing the Hotspot immediately after disabling it, and also doing the same thing for the "Object to hide" (and checking for it's presence in between the two).  You should simplify this as much as you can to reduce the number of Actions you have to deal with going wrong.

    A Hotspot prefab cannot make reference to a scene-based Interaction because when you close the scene the connection is broken.  To get around this, the Actions source field can be set to Asset File to allow you to have its Actions outside of the scene and have a Hotspot prefab work normally when spawned in a scene.

    If a Hotspot's Interaction or ActionList contains a GameObject parameter, then you can set the value of that parameter to be the clicked Hotspot.  For simplicity, you may want to see if you can merge the Access Card mesh and Hotspot together (i.e. make the mesh/Animator of the Hotspot) so that you only have to deal with one object per spawn.  Removing the Hotspot will then cause the mesh to also be removed.

    As your Hotspot's Constant ID is set to "Retain in prefab", it will have the same Constant ID in the scene - as will all clones of it.  AC requires that all scene objects have unique IDs so that assets can correctly distinguish between them.  If you uncheck Retain in prefab?, then each Hotspot clone will have a unique ID number that you can make use of.  The same should go for the "AccessCard" mesh you're also spawning.

    When spawning items outside of AC's provided Actions, you must call GatherSceneObjects in order to have AC update its internal record of objects it can affect.  Code for this is provided in the front page of the scripting guide.

    Your SpawnItems script stores each cloned object within the same variable.  itemClone will only ever be set to the last-spawned item, since it is being overwritten each time.  You also don't need an array of items / itemHotspots, since they all have the same value.

    So, I'd suggest:

    1) Merge the Hotspot / card mesh prefabs and uncheck Retain in prefab?
    2) Move the "when clicked" Actions to an asset file and have your Hotspot prefab run that when used.
    3) Use a single "GameObject" parameter and set that dynamically to be the Hotspot from within the Hotspot Inspector.

    If you do need more differentiation in the Action fields when the Hotspot is clicked (for example, to change the added inventory item dynamically) you could feasibly write a custom Action that changes the parameter values through script.  Parameters don't need to be set purely through the ActionList: Run Action - but lets see how you go with this first.
  • Thank you so much Chris, I've carefully followed your suggestions and the three steps you listed, I've tested extensively and I am now getting the desired results. Really grateful, and thank you too Alverik for your comment, your explanation about Constant IDs and duplicated objects added some clarity as well. 

    I'm including two screenshots from the solution showing the refactored Action List and the combined gameObject  / hotspot's inspector in case it helps anyone else having similar issues in future. 

    image
    image
  • Ah, sorry, parameters slipped my mind. I do have a very particular way of doing things... If anything will need to be repeated many times I prefer to hand code it into a single script or custom action.
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.