Forum rules - please read before posting.

Add or Remove not removing an Object

edited March 19 in Technical Q&A

Hello! I'm Using Unity 2022.3.21f1 and AC 1.80.0

I'm trying to create an ActionList that instantiates a prefab and positions it in the same place as a Hotspot. If there's a GameObject in that Hotspot already, then delete the current GameObject there

What I'm doing

  • I've created an Asset File (because I have several Hotspots with the same behaviour), this is what it looks like, it includes two Properties, one that stores the Hotspot Position, one to reference the current GameObject (if any) in that position.

  • This is what the prefabs look like. The Prefabs are associated with Inventory items, hence the Scene Item Component in it.

The ActionList have three actions:

  • Remove the GameObject (if any)
  • Create a new GameObject via Inventory : Scene Item, then set it to the CurrentHint ActionList Property
  • Set the parent of CurrentHint as HotspotPosition

Oddly enough the GameObject creation and re-parenting are working fine, the one action that is not working is the Object Remove. And if I add a Remove Action right after the Set Parent Action, it actually works (but then it removes the Object I have just spawned :)), so Remove only doesn't work if it is the first action of the ActionList... I can't figure out what I am doing wrong... Any ideas?

Thanks!

Comments

  • It'd be down to what the value is of your "CurrentHint" parameter at the time the list is run.

    Are you setting it inside the ActionList: Run Action, or by some other means?

    If "CurrentHint" is set to an object in the scene, it should remove it without issue.

    If it's instead set to a prefab (i.e. the original asset file), and you want to remove the instance of that prefab in the scene, you'll need to make sure that AC can connect the two together.

    This can be done by checking Retain in prefab? in the Constant ID component, which causes the prefab to have an ID number that will be shared by instances of it in the scene. When the Action is told to remove a prefab with an ID number, it will attempt to remove an object in the scene that shares the same number.

  • edited March 20

    If "CurrentHint" is set to an object in the scene, it should remove it without issue.

    I believe it is, check the three screenshots below

    • The first one is the state of the Hierarchy and ActionList local parameters, you can see that Hotspot_Hint1 have no children and the CurrentValue of CurrentHint is empty

    • After running the action once, Hotspot_Hint1 have a children and the CurrentValue of CurrentHint has the same name as the GameObject created

    • Running it once again, CurrentValue of CurrentHint is updated to the new GameObject and the Hotspot_Hint1 have a couple of children, when it should have only one.

    Now I'm not sure if CurrentHint is referencing the instance or the Prefab, however, if I call an Object : Add Or Remove immediately after Object : Set Parent referencing CurrentHint the GameObject IS destroyed, but if I call it as first action of the ActionList (as in the original image) it doesn't work, because of that I assume that CurrentHint is referencing the instance.

    EDIT: So I've added a couple of comments like this

    • On Action 0, [param:1] is always the same ID (I've added it to ensure that I was calling the same hotspot and not a different one by accident), but [param:2] is always empty, even after I've created an object and set it to the CurrentHint parameter

    • Now here's where it gets interesting... On Action 3 when I print [param:2] I DO get the ID of the GameObject that I have just instantiated, and checking in the Inspector the number matches with the ConstantID component.

    And adding a breakpoint to Action 0 I now noticed that that CurrentValue is empty again... Why would that be?

  • How are you running the Interaction ActionList, and are you setting parameter values at that time? It may be that you're setting HotspotPosition to your intended value, but inadvertently resetting CurrentHint.

  • OK, just figured out the issue and now I want to kick myself in the head.

    Before creating an ActionList Asset I was using a Set interactions Parameters Component to set the parameters values, and I was setting CurrentHint
    to (you guessed it!) None... Disabling the component and now it's working...

    Thank you for your help @ChrisIceBox !!!

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.