Forum rules - please read before posting.

Allow object to be destroyed after it's been duplicated

edited August 2015 in Technical Q&A
Hello Chris,

Since this is the first time writing here I'm gonna start by saying congratulation for this amazing tool kit. 
Now, on to my problem :D 

What I'm trying to do is this:

- Place an object in the scene
- The character interacts with the object 
- That object is destroyed 

The catch is that I want to duplicate that object as many times as I want and the behavior to remain the same.

Using the Actions from AC, I can delete the object using Object - Add/Remove, but the gameobject field doesn't update when I duplicate the object.   
image

I've thought of a work around, but I'm having some problems with this one too. 
I thought of using Object -> SendMessage and send a message to a script that is in the Action. The script would then delete the object attached in it, since the gameobject field from the script updates after I duplicate the object. The problem here is that I don't know how to send a message using the Action from AC and still make it work after I duplicate the object, since SendMessage uses the same method as Object - Add/Remove from above. 
image

Btw, I'm still learning C#, so I mostly know the basic commands and stuff. 

Thanks a lot and hope you can help me with this. 

Comments

  • Welcome to the community, @Stefan, and thanks.

    If you need to reference GameObjects that are not in the scene, you will need to reference their Constant ID number instead.

    Try dragging the prefab of the GameObject into your "Object: Add or remove" Action instead - it will generate a new ConstantID number for you, which will show up beneath the GameObject field.  When you switch scene or re-start Unity, the field will be empty again, but the number will still show.  This is how AC keeps track of objects that are not in the same scene as your Action.
  • edited August 2015
    Hey Chris, 
    I think I didn't explain the problem correctly. What I'm trying to do is make a global Use action that does this when it's attached to a Hotspot :

    1. animate character 
    2. add item to inventory
    3. destroy the object that was used 

    So, this action would have to work on any object that has the component Hotspot with this Use object.
    Basically in the "Object to delete" field instead of having a specific object, there should be "Last object used".
    image

    An example of how I want to use this is :
    I have 100 rocks on a beach. Each rock is actually a duplicate of a single rock that has a hotspot component with the Use Interaction described above.
    If I use any of the rocks, the character plays the "pick up" animation, a rock is added to the inventory and that rock that has been used is destroyed. 

  • First off, I'd recommend you look into parameters, if you haven't already - since they can be used when you want to "recycle" a chain for Actions for different objects.

    Your specific requirement of removing the last-used object is heavily-tailored to your game, so I would say that a custom Action to do this is what you'd want.  Custom Actions allow you to do basically anything, so I'd recommend you look into them.

    You can get the currently-active Hotspot with the following C# command:

    AC.Hotspot currentHotspot = AC.KickStarter.playerInteraction.GetActiveHotspot ();

    So, to get the most recent Hotspot, you'd want something like this in a C# script's Update function:

    AC.Hotspot lastHotspot;

    void Update ()
    {
      AC.Hotspot currentHotspot = AC.KickStarter.playerInteraction.GetActiveHotspot ();
      if (currentHotspot != null)
      {
        lastHotspot = currentHotspot;
      }
    }


    You can then retrieve the value of lastHotspot in your custom Action in order to destroy it.

    You can see the entry for the PlayerInteraction's GetActiveHotspot function in the scripting guide, as well as all of AC's public functions and variables.
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.