Forum rules - please read before posting.

Spawning Items in a Scene

edited December 2014 in Technical Q&A
Hi,

I've been working on a system that will spawn a random item in the scene that the player can pick up and have placed into their inventory. None of the items are placed in the scene before the game is run, just spawn points that indicate where items can appear. 

My questions:
* Is there any built-in way to spawn an item into the scene with a unique interaction script that will point to that game object, hotspot, and inventory item?

* For the ActionListAsset, is it possible to set a hotspot as a parameter that can be passed in?

Currently I am attempting to instantiate the Interaction script  and set the parameters for itemID for the inventory item as well as the game object that holds the sprite renderer for that object in the scene and the hotspot that should be disabled.

I currently attempt to create an instance of a prefab that has the sprite renderer and a constantID script on it along with another script that contains the inventory item ID. Nested within this is the hotspot script with no use interaction associated with it yet.

There is an interaction script in my scene that calls Engine: Run ActionList and points an an ActionListAsset file that contains the following actions:
* Add or Remove Object
* Hotspot Change Interaction (to disable Use)
* Inventory Add or Remove

I create a clone of the interaction script in my scene, and then set the parameters of the ActionListAsset to point to the instantiated game object with the sprite renderer etc. so that when it runs it will remove the object from the scene. I also read the itemID and set the intValue member for the second parameter which is used for the Inventory Add or Remove action.

When I run this however, it doesn't appear to save the references I set for each of the spawned objects in the scene and instead shows None for game object, and None for inventory item, although I can clearly see them set with breakpoints after each in my script where I set them.

Here's a link to the code snippet I'm using to do this.

Comments

  • Wow, this is quite complex!  Kudos for having gotten a ways into this already.

    Is there any built-in way to spawn an item into the scene with a unique
    interaction script that will point to that game object, hotspot, and
    inventory item?
    The Object: Add or remove Action can be used to instantiate prefabs into the scene.  To make sure the prefab gets added/deleted properly with save games, give it a RememberTransform script, check "Save scene presence" and place the prefab in a Resources folder.

    For the ActionListAsset, is it possible to set a hotspot as a parameter that can be passed in?
    Hotspots and other objects can be passed in the GameObject parameter - the object type should be found automatically by the receiving Action.  What Action are you trying to pass it to?

    There is an interaction script in my scene that calls Engine: Run
    ActionList and points an an ActionListAsset file that contains the
    following actions:
    The Engine: Run ActionList Action sets the asset's parameter values just before it runs the asset.  Your script assigns the paramter values, but they'll get overwritten by the Action.  There are two workarounds:

    1) Bypass the Engine: Run ActionList Action completely - just call runtimeActionList = AdvGame.RunActionListAsset (_assetFile, 0); to run it manually after assigning the parameters.

    2) Manipulate the Engine: Run ActionList's "assining" parameters instead - not those of the asset file.
  • edited December 2014
    For the Hotspot game object, I'm trying to pass it to Hotspot: Change interaction, but even with a Game Object parameter defined under parameters it doesn't display a drop-down to select a parameter for that action. Is this a bug? Or did I miss a step? The other actions both pop up a drop-down to select a parameter just fine.

    Thanks for the information on the other questions! I'll try option number 1 and see if I can get the other parameters to populate properly.

    Edit:
    Looking at the ActionRename and ActionInteraction scripts, I noticed that ActionRename calls Action.ChooseParameterGUI to show the drop-down, where ActionInteraction does not. Also the ShowGUI function takes a list of parameters in ActionRename but not in ActionInteraction. Maybe I'll try a re-import to make sure it's updated to latest.
  • I tried downloading and importing AC into a blank project again and it looks like that parameter GUI creation call is still absent from the ActionInteraction script. Maybe it got overlooked for whenever passing parameters via actionlists was introduced? 
  • It wasn't - it's left out of that action intentionally.  The Hotspot: Change interaction Action needs to know exactly which Hotspot it's affecting before it can show the appropriate options.  What are you trying to do with the Action, exactly?  The Hotspot: Enable or disable Action should still work with parameters.
  • Ah, you are right, I was just disabling the hotspot, and come to think of it, I'm removing the game object altogether when I pick up the item, so it's not even needed to disable it. Thanks for the clarification!
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.