Forum rules - please read before posting.

Object: visible/hide and inventory counting

Hello there AC'ers.

I posted another thread about a decoration game I want to make.
I have gotten a little wiser and therefore would like to ask a technical questions.

If I, say have a default chair in my scene and when I click the inventory item of another chair and it's set with action to be object: visible - how would I then "hide" the chair that is in the scene already? The chair will change, ie if the new was selected - and then if another one i selected that will be swapped etc. So it's never a "fixed" chair that it is in the scene.
Not sure how to accomplish that?

Would appreciate any direction

Best regards and Happy Easter

Cheers, Dan

Comments

  • The approach usually recommended is to teleport the object in question (in this case the chair) to some marker far away in the scene, out of view of any game cameras, and teleport the new chair into the location of the original char (or rather a marker in the relevant spot).

    This way it's easily handled in action lists.
  • Thanks for the reply,
    If I teleport, how will I know what item is 'active' in the scene and can 'hide' that?
    (I'm not sure how I know what is currently 'the chair that is in the scene, how I 'detect' that, so I can hide it when. It might be objects from varies inventories (to mimick 'tapped' categories) and whenever an object is tapped in the inventory, it should appear at a fixed position, hiding the one that is already there.

    If I have, say 1000 items, will the scene be very heavy mobile?
  • edited April 2017
    Well that's a good question, but it depends. In the first place creating and then destroying objects constantly is already bad practice (Unity's garbage collector will kill your game if you do that -ie: lots of lag spikes). So it depends on how you want the game to work or look, and how you want the player to pick the object variations. 

    What I'd do is keep a pool of active objects. When starting the game, there could be one of each base model loaded. But i'd try to use the same model for as many variations as possible. ie: I have 2 chair models, each a wildly different mesh, then I'd use each base for all colors, or all different textured versions (by changing just the color or swapping the material), that'd lower the number of objects I'll need to have loaded in the level (when the player tries to swap out the object and it uses the same base). That way you'd have ie: 3 chair models, 3 tables, 3 tvs, etc. Then if the player buys one more than what you have in the pool, then, and only then, do you add a new copy of a base object.

    If the way the player will pick the items is made in a way that the items won't need to be spawned and destroyed constantly you could also give that a try, but as I said it's usually not the best, some sort of pool of objects is usually the best when you are going to have a large amount of objects. But the way you picture the mechanics will change how to deal with the situations. In general when the player tried to swap the item I'd have an actionlist on the object to swaps the materials/colors if the new object is part of the base, else I'd do the replacing the active object for another one in the pool. You'd have to start by testing with say 2-5 items, once you get how to do it correctly it'll be easier to apply the same technique for a lot of objects. Yet again, if you made the game 2D you could just swap the sprite/textures and be done with it, lol. But as I said it depends on the type of game you have in mind.


  • edited April 2017
    Thanks a bunch Alverik.
    Awesome, so that has been sorted out then. I saw it kind of like spawning particles, bullets etc - that I wouldn't want it active all the time. But I get it. Makes sense :)

    Replacing textures is a great way of giving some "customization" options for the player.
    I will definitely include that. The logic to set that up is also pretty straigtfward with the limited knowledge I have so far - but here is the thing that my mind still can't figure out.

    The logic to "swap" unique meshes. My items will be presented in an "inventory" (with no drag and drop, but simply a "menu" of items that the player can press/tap and then they will show at a fixed placed in the world. (so I ie have a button of a chair - pressing that will open up the "chair menu")
    With my very limited knowledge, I will be able to have teleport the object to a marker - but on that marker there will already be another item that would need to be teleported away - and that logic I need to "identify" that exact item (which can be any of all the items in the "inventory" menu).
    How can I find out what the item is so I can "hide" it? (I guess teleporting it back to the others in the pool?)

    Hehe, I can see what you mean with the sprites - that darn 3d meshes! ;)
    Cheers!
  • edited April 2017
    The answer is variables. You can use them to keep records and such. if it's only about knowing if there's something in your spawn spot, then you could make a local/global bool variable, like: IsItemAtSpawnPoint. Whenever you spawn an item turn it true, and if the player tries to spawn another item while the variable is true, then don't allow spawning. Then you could have a trigger for example, checking if an item/object is still in the spawn spot with the OnExit and/or the continuous trigger options (changing IsItemAtSpawnPoint to true here would probably save you the trouble of doing it elsewhere).

    You can put two AC_Trigger scripts on the same trigger, set one to Continuous and the other one to OnExit. Then on the continuous one you'd turn the variable true as long as there's something inside, on the OnExit you'd turn the variable false once the object leaves the trigger(you could have only the OnExit too I guess if you want to save some performance). 

    If you wanted to replace the spawned item (instead of just blocking the player from creating a new item)... First you could make a second bool variable (like: ShouldTeleport or ShouldRemove), then if IsItemAtSpawnPoint is true and the player clicks an inventory slot then you can make ShouldRemove true. To make this useful you could go to the AC_Trigger script set to Continuous, check Set Collider as Parameter. Now you'd need a Variable:Check action to check if ShouldRemove is true. Following that you could make an Object:Teleport or an Object:AddOrRemove actions and set the target object to be the collider in question (which will be available as a parameter). That way if ShouldRemove is true, then AC will remove the item (in contact with the trigger), finally the last action would be a Variable:Set where you'll turn ShouldRemove back to false. 

    You'll most likely have this working in parallel to the Variable:Set for IsItemAtSpawnPoint (which I mentioned earlier) by using ActionList:RunInParallel, with that action you can have several lines of logic running at the same time inside the same actionlist.

    Of course, these are just ideas, if you can make it better after some thinking that's always great. Still, global or local variables are going to be key.
  • Thanks a bunch Alverik.
    Hmm..gets a bit more complicated with the variables..but I get the overall concept.
    Thanks for the enlightenment :)
    Another way I thought I can "cheat" is basically to have an object that is "larger" then the one that is already there..hence hiding it. Obviously this will not work if player has to be able to go back to one that has already been in the scene.
  • edited April 2017
    Don't worry it takes some practice to get used to using variables (Same with triggers). For variables in AC it's easier if you've learned some programming before. It might pay off to get used to using them before you delve deeper into game development (AC or not, triggers and variables are a key aspect in game development, you'll be using them a ton, so no matter what you do, you will get used to them, lol).
  • These things are always best done with custom Actions if you have the know-how, but ActionList parameters are another way of streamlining your ActionLists when you want to manipulate many objects in your scene in a similar way.

    You could, for example, create an ActionList that hides all chair sprites in your scene and then re-shows just one of them - and that one is set dynamically with a GameObject parameter.  Have a look at that tutorial and see if that's relevent for your situation.
  • edited July 2017
    Instead of having tons of actionlist parameters for each item in a specific category (meaning the list could be very long)
    Would it make sense to have  custom script where I use tags, so ie for the decoration say I have a category that is "hair"..
    Then have a tag with hair and tag all hair items with that tag.
    Then have a custom script that similar to this one something along then line:



    GameObject[] gameObjectArray = GameObject.FindGameObjectsWithTag (“Hair”);

      foreach (GameObject go in gameObjectArray) {       

      go.SetActive (true);

        }


    And then after that that actionlist node, have a another one that teleport the new object to the marker
    With ActionList parameters I seems like I would still need to add each single item, since I can't use a "tag"/"category.

    Any direction would be much appreciated.
    Thanks a bunch 
    Cheers, Dan

    (I have NO idea why the CSS is added below - it's not here in my post! Sorry for that)

    p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
    li.li2 {margin: 0.0px 0.0px 0.0px 0.0px; line-height: 16.0px; font: 13.0px Courier; color: #323333; -webkit-text-stroke: #323333}
    span.s1 {font-kerning: none; color: #2c91af; -webkit-text-stroke: 0px #2c91af}
    span.s2 {font-kerning: none; color: #000000; -webkit-text-stroke: 0px #000000}
    span.s3 {font-kerning: none}
    span.s4 {font-kerning: none; color: #018000; -webkit-text-stroke: 0px #018000}
    span.s5 {font-kerning: none; color: #813500; -webkit-text-stroke: 0px #813500}
    span.s6 {font-kerning: none; color: #a31516; -webkit-text-stroke: 0px #a31516}
    span.s7 {font-kerning: none; color: #008de4; -webkit-text-stroke: 0px #008de4}
    ol.ol1 {list-style-type: decimal}

    p.p1 {margin: 0.0px 0.0px 0.0px 36.0px; text-indent: -36.0px; line-height: 16.0px; font: 13.0px Courier; color: #813500; -webkit-text-stroke: #813500}
    span.s1 {font-kerning: none; color: #2c91af; -webkit-text-stroke: 0px #2c91af}
    span.s2 {font-kerning: none; color: #000000; -webkit-text-stroke: 0px #000000}
    span.s3 {font-kerning: none; color: #323333; -webkit-text-stroke: 0px #323333}
    span.s4 {font-kerning: none; color: #018000; -webkit-text-stroke: 0px #018000}
    span.s5 {font-kerning: none; color: #813500; -webkit-text-stroke: 0px #813500}
    span.s6 {font-kerning: none; color: #a31516; -webkit-text-stroke: 0px #a31516}

    p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
    li.li2 {margin: 0.0px 0.0px 0.0px 0.0px; line-height: 16.0px; font: 13.0px Courier; color: #323333; -webkit-text-stroke: #323333}
    span.s1 {font-kerning: none; color: #2c91af; -webkit-text-stroke: 0px #2c91af}
    span.s2 {font-kerning: none; color: #000000; -webkit-text-stroke: 0px #000000}
    span.s3 {font-kerning: none}
    span.s4 {font-kerning: none; color: #018000; -webkit-text-stroke: 0px #018000}
    span.s5 {font-kerning: none; color: #813500; -webkit-text-stroke: 0px #813500}
    span.s6 {font-kerning: none; color: #a31516; -webkit-text-stroke: 0px #a31516}
    span.s7 {font-kerning: none; color: #008de4; -webkit-text-stroke: 0px #008de4}
    ol.ol1 {list-style-type: decimal}
  • If you're teleporting objects in and out of view, there's no need to also disable/enable their GameObjects.  If you want to affect objects in bulk, just move them all to the same location off-screen, i.e.:

    go.transform.position = new Vector3 (0f, -1000f, 0f);

    That can be done regardless of however you show the "correct" object.

    So far as using parameters goes, I was thinking you'd only need one or two.  You could refer to GameObjects by Constand ID - just attach a Constant ID component to an object, and it'll be assigned an ID number that is unique to it in that scene.

    You can then enter that number in as a GameObject parameter's value when using the ActionList: Run Action.

    Alternatively, you could just script the whole thing.  These are Hotspot inventory interactions, correct?  You can set the Hotspot's Interation source field to Custom Script, which allows you to run custom script functions instead of ActionLists.  If the function that is used for inventory interactions has an integer parameter, that parameter will be set to the ID number of the inventory item - allowing you to script an appropriate reaction accordingly.
  • Thanks Chris.
    I solved it by making an empty gameObject with the general category name. Than placing each item in that category as a child.
    Creating an ActionList with Object:Visibility with the empty parent gameobject and checking "affect children".
    Then using another action that sets the the chosen item visible.

    It seems to me that this would also work with Character Customization as-well, ie hair, clothes etc, even when the character is animated, since all gameobjects are parented to the character, where as the teleport seems to work only on static positions.

    In terms of the hotspot inventory interactions, I'm using context sensitive and using "use interaction" on the specific item.
    I have made some "fun" interactions, where ie player can press a trigger on a dandellion and it shoots of a particle system with dandellion seeds. when doing that, the inventory menu appears - in another trigger I have where I use a switch camera and after back to gameplay, no menu appears.
    I don't want to the menu to appear on these events - but can't seem to find the pattern on why it appears on one and not the other - is there a way to have it not appear for certain events?

    I'm still having some issues with the buttons "flashing", despite having made an actionlist where I have chosen run in background - if I set the appear type to manual it disappears completely ?



  • Were some of these issues from another thread?  I can't see mention of the flashing / inventory issues further above.  My apologies, but with so many threads it's hard for me to keep track sometimes.

    If your Interaction method is set to Choose Hotspot Then Interaction / Choose Interaction Then Hotspot, then you can check Single 'Use' Interaction? in the Hotspot Inspector to emulate Context Sensitive mode on a per-Hotspot basis.

    Otherwise, you can use the Menu: Change state Action to lock / unlock your Inventory menu from appearing even when its Appear type rule is met.  These can be placed in ActionLists triggered by the Hotspot's "Highlight object" events if need be, but it could also be scripted.

    Regarding the flashing issue, know that you can check the game's current state by checking List active ActionLists in Game window? at the bottom of the Settings Manager.  Also, be sure to use the latest version of AC (backing up your project first).  Which buttons are flashing, and what was the Appear type of the Menu when not Manual?
  • edited August 2017
    Sorry for the confusion, no wonder it's hard to keep track :)
    I'll make sure to have a specific discussion in one thread.

    In regards to the flashing issues of the buttons, it was due to the fact that you mentioned that it needs to run in background and not "during gameplay". You also mentioned the appear type should be set to manual. My buttons disappear from the screen when I do that - so I guess I have missed out on something?

    In regards to the interaction method; i have set the interaction to hotspot then interaction and used the Single 'Use' Interaction.
    I have several hotspots where I use that method on, one is a camera panorama of the world, and it works perfectly, revealing the scene and then goes back to to gameplay. No menus or nothing.
    Then I have an object the player can tap and a particle effect will play. But here the menu appear!
    I don't understand that, since both a done with with the use interaction and have single use interaction, so they should be similar. Not sure why.

    When I click a hotspot that has a menu interaction, it shows all the various menues I have created - should these instead be called with actionscripts or what is best practive?
    When having just one, it's pretty easy, ie similar to the tutorial, but I have a lot of different ones.
    Chosing a hotspot make all the InventoryBoxes appear at once(even one that is for something totally different (collectible).

    I also noticed than if I select one of decorations where a menu appears (which it should) and I then right after tap ie the trigger for the panorama shot mentioned above (the one that doesn't have a menu appear), the menu now appear and it shows the label on mouse over. 

    Btw, is there  a way to have the player control the "camera" ? So the player can use their finger to pan around the work and fingers to zoom in and out(ie if it was a top down view) ) (kind of like the same way in many building games, farmville, Hayday etc) ?

    On a site note: I played with setting up a character with the wizard.(I already have a character in, that I set up manually with mechanim), When the player has been created - it is hovering? Like flying above the ground as if hovering up and down as if she is sitting in some kind of jetpack or something, and despite if I use the character controller I have made for the character I manually I set up, it doesn't overwrite the hovering. 
    Is there a way to get around it?

    Love the tool! Still blown away by all the small details and things that have gone into the pack and how much is possible without a single line of code.
    It's a joy to work with - and thanks for all the amazing help! 



  • No problem - if in future, you could all issues in separate threads, however minor, that would be great.

    In this thread, I suggested restyling the Interaction Menu to look like the "bottom" one.  How did that go?

    I feel that at this point we're more bogged down with issues related to the way things are set up in the game, without addressing what it is exactly you want.  If you would like to instead explain the gameplay you're wanting to achieve, it may be easier to cover the steps to achieve that instead.

    However, if you want your Inventory menu to appear when clicking on a Hotspot - and for clicking those items to instantly "use" them on that Hotspot, then your InventoryBox element must be placed in a Menu with an Appear type of On Interaction, and the Inventory box type field must be set to Hotspot Based.  These settings will cause the following:

    1) The Menu to appear when a Hotspot is clicked (provided that Single 'Use' interaction is unchecked)
    2) Clicking items in the Menu will automatically use them on the Hotspot.

    It shouldn't be the case that any Menus with a different "Appear type" should show, and this behaviour is basically the same as the 2D Demo.  The 2D Demo, however, allows you to also "Use", "Talk", and "Look At" Hotspots in the scene, and this is because the Interaction menu contains Interaction elements for each of these icons alongside the InventoryBox (as you've seen).

    Removing these interaction elements from the default Interaction menu will cause only inventory items to show, and you can restyle it so that it sits along the bottom.

    You will, however, have to amend your Close interactions with setting to Click Off Hotspot so that the Menu doesn't close when the mouse leaves the Hotspot to reach the Inventory menu.  Or, as I mentioned in the other thread, make the Menu cover the whole screen (but invisibly) so that the mouse/cursor/tap technically never leaves it.

    Regarding the menus appearing when the particle system plays, please post this in a separate thread showing screenshots of the Hotspot Inspector, the ActionList, the properties of the Menu which shows, and anything else that might be relevant.  It may be there's some minor difference with those that work which has been overlooked.

    So far as the flickering goes, which Menu are you talking about?  When I suggested turning it to Manual, I was referring to the "InGame" menu - not the one that shows the Inventory.  The "InGame" menu is the one in the lower-left corner to open up the Pause menu.  This, too, can be restyled to suit.

    For the "floating" character, check that the character's model/rig child objects have (0,0,0) positions so that they are at the centre of the root object.  This may be an animation issue instead - sometimes when importing animations, Unity will adjust the Y position - particularly if it uses root motion.  You can prevent this by going to the animation import settings when viewing the animation/model file's Inspector - but if this is the case, then it's a Unity issue rather than an AC one.

    Re: controlling the camera - AC also has a "GameCamera 2D Drag" prefab available for 2D games, which allows for dragging the view around.  Though you're working in 3D, it may still work for you - try dropping it into your scene (it's in Assets/AdventureCreator/Prefabs/Camera).  Note that using it in v1.58 currently shows an error, though this will be fixed in the next release.  Otherwise, you can rely on a custom camera script that behaves the way you like.  Incorporating custom camera types into AC is covered in the Manual - section 4.2.7.
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.