Forum rules - please read before posting.

Activating\deactivating GameObjects

2

Comments

  • I'm going to alter the action scripts as soon as I can. These were written not to be used in assetlists but to be used in-scene and I think that's the problem. Looking over the demo assetlists these are general actions such as sending a message and don't deal with the objects in the same way as far as I can tell. Possibly if you let me know exactly what you want these actions to do and why they have to be referenced in an actionlist I can code them correctly.
  • Thanks a lot. 
    Unfortunately I don't see any way to run my specific need in the scene, due to how AC is set up at the moment as the Use interaction needs an asset file. Otherwise I wouldn't have bothered you.
    What it needs to do is simple in this case: as I said before, the .asset file is run on the "standard interaction" ->  "use" of the inventory. 
    You find it in the Inventory tab of AC's Game Manager window, for example if you select the word in the demo scene inventory.

    This means that in my game, when you click on an item on the inventory, that item appears. It's the only way that I could think to simulate an FPS inventory system, where your character can switch through his items and they appear in his "hand" (note, there are no hands in my game though). Otherwise, I'd be forced to constantly have invisible items flying in front of my character, but then I'd have the problem that their colliders are still active and it's also a waste of performance\loading times.

    I haven't decided how to let the player deactivate it once you set up an item, yet.
    I tried UFPS but it gave me a Lot of problems, mostly bugs with the cursor and the hardship of combining their inventory system with AC's, all stuff that could be down to my incompetence, and I didn't want to bother Chris more than the necessary. 

    I will correct the script and test like you did even if you say that it doesn't work correctly.
    Maybe @ChrisIceBox has some tips for you.

    Unfortunately I'm a noob when it comes to programming this way. I can read and understand a script, but if you ask me to do it from scratch we can have a nice laugh :D
  • edited November 2014
    Just run another test: trying with the add\remove gameobject I run into the same issue. This is impossible, I thought...

    "and it may be an assetlist needs to be put in a resources folder to run, unfortunately I have no time to look into it further tonight."
    And, infact, it seems that InvActionLists need to be stored in a InvActionLists folder - at least that's how it is in the demo, and how that problem disappeared. Stupid me. 
    The bad news is that it suprisingly, it didn't work with your action to me :/ (the problem didn't go away). 
    What's weird though is that I also tried 

    GameObject newObject = myActivate;
    newObject.SetActive (true);
    in place of myActivate.SetActive(true); but actually, nothing changed to me.

    Just a side note, though: I noticed that with the Add\Remove action a ConstantID is automatically added to the gameobject - and this is shown in the ActionList itself actually (try). This is in the manual under "9.2 - SAVING INDIVIDUAL OBJECTS". I'm not sure if the lack of this component is part of the problem? hmm, I tried manually adding one and nothing changed, though - even if it's still not referenced in the ActionList himself.
  • The problem lies in actually activating and deactivating objects. An object deactivated in the scene does not have a listener so a send message cannot be received so setting up a send message similar to the particle switch script will not work because there is nothing there to listen, basically activating a deactivated object has to be dealt with by a script similar to how it is setup there.

    There are work arounds but as its not my project I don't really know what you wish to do. A script could be put on the camera that could recive a message and switch on an object, You could disable the renderers of the objects as well as the colliders, these could then be enabled using the turn on and off functions already setup so in effect you would be swapping through weapons easily because they still exist in the scene constantly.

    I use these deactivate and activate scripts to turn on minigames not inventory items.

    It could also be done using delegates but one always needs a listener in the scene.

    As regards the saving individual objects I am not certain either, however, at a rough guess I would say that is only to save objects when the game quits so that it keeps them as they are when it is next loaded. You can also use make visible, especially if the objects are in a set area, lok at the 2D demo for how that can work.

    I don't know enough about AC to be of much assisstance, and I often go long periods without programming at all so I often forget basic things about Unity until I get going again. In this case though I'm pretty certain about the constraints on deactive objects.

    You don't need to do it the same way through the inventory, assetlists are scene independent  but you don't have to set it up that way, you can do it on a scene by scene basis in which case the scripts will use in-scene and not asset file and will work. 
  • Hi, unfortunately in my case it would be better if it was scene-indipendent - besides I'm not really sure how I could set them up since the Standard Use Interaction requires a external asset ?

    As for the listern thing, how does the Add\Remove function works, though? I'd assume a removed object doesn't have a listener object either, so... wouldn't it be possible to use the same logic ? I'm not good enough unfortunately, but thank you for your assistance =)
  • That's quite a wall of text to decipher, but generally there's two things to keep in mind when using the Object: Add or remove Action:
    1. Add a Remember Transform script to the object, and check both Save scene presence, and Retain in prefab.
    2. Place the object as a prefab inside a Resources folder
  • Hi David

    Sorry I couldn't be of more help, I haven't yet dug deep into the inner workings of  AC I just dip in once in awhile to make sure what I want can probably be done, so far I've just done those scripts set up hidden object games and a crude hint system that works for me, but haven't yet started figuring out exactly how to do things the AC way, I'm just well versed in polishing turds when it comes to games so I know there are many ways to do a task. It's hard to figure the best way forward without looking at a project, understanding what the developer needs, and a fairly in depth knowledge of the tools at hand and the latter I don't have yet.

    Good luck with the game.
  • no worries, you were much of help actually.In the end you provided a script that in-scene, works. It's up to me to figure something ;)

    haha sorry for the wall of text, Chris. 
  • You know you can simply stick those scripts on the player which means they will be in every scene and can reference what you want without the need for an assetlist, Unity is built this way as are all the assets that plug in to it.
  • you are right, the problem is that I don't know how to reference "use this when you click on this inventory object". Normally, this is done via AC's UI. I'll try to have a look at AC's code, but it'll take a while.
  • Well for that particular inventory item instead of setting the use: to assetlist you set it to in-scene, then you simply use the actions as you wish. You don't throw the scripts on the player at all. I vaguely remember that the item referenced by these scripts has to be in the scene so you won't be able to use a persistent player prefab that is moved from one scene to the next, instead you have to play pass the parcel with variables via the global variables function and get any changes when the scene loads otherwise a null reference will be thrown if you try to reference something that is dynamically loaded into the scene at runtime, at least I believe that to be the case, but I am somewhat rusty with coding in Unity. Might be worthwhile just testing that, unless someone more experienced chimes in and clarifies things.
  • edited December 2014
    Well for that particular inventory item instead of setting the use: to assetlist you set it to in-scene

    yes, but how? This is what I'm missing here, apologies =p
  • I assume the item is attached to the player as it is supposed to be a weapon swap? I may have gotten that wrong.

    So when you look at the use:sword interaction in the inspector tab, at the top is the interaction properties of the interactions script. The first item down is actions source. Set this to in-scene and not asset file.

    Assetfiles are only of use for scene independent items such as the inventory, however, one doesn't need to use an asset file for every item in the inventory and many items that are only in one scene one would not use an asset file resource for anyway.
  • edited December 2014
    Sorry for the late answer but I tried to investigate this a little before coming back. 
    Unfortunately I'm still not sure how to do it , maybe it's possible via scripting but right now I'm not sure.

    The problem, as I said, is that this action runs on the "Standard Interactions" of the inventory, and that one requires an asset file naturally.  It means "run this action when you click on the image of the item in the inventory" - it is not run on an the action of a gameobject that I can find in the inspector tab.

    So, what I need, is that you click on an inventory icon (which is GUI), and an action is run.
    Is there any way to do this in-scene ? I'm not sure how to achieve it. Maybe I'm missing something obvious though...
    Otherwise, you'd be able to activate the GO only through an hotspot. Which would basically kill for the player the possibility to activate and deactivate the GO whenever he wants (which in my case means taking off and taking on a weapon).

    That "use: sword interaction" you were referring to doesn't even exist in my scene - even if it existed, I wouldn't be able to use it as it would need to be attached to a game object, but I can't attach it to the weapon itself, because it needs to run when you click on the weapon's icon in the inventory.

    Even if I attached an interaction script to the weapon, the problem would still be that I don't know how to "link it" with the fact that it needs to run when the GUI icon on the inventory is clicked on

    Not sure if I made myself more clear :/

    It's a problem because basically, my inventory would be useless currently, as what I need the most is that when you click on its icons, a game object is "spawned" in front of the player.

    edit: actually an alternative would be to use AC's "visibility". The problem is that this effectively means that my player has various weapons in front of him that are invisible - problem being that their colliders, well, aren't "invisible", so it feels weird when you go against a wall :/.
    The second (big) problem is that the flashlight also has a light component and a script attached to it that works when you press the right mouse button... so I'd have to access AC's source code and learn how to detect via script if an object is invisible or not, and add an if to my script which says if GO is invisible, then "don't work". And it's too hard for me, besides there's the other problem. Also, I don't know if AC's "invisible" also means that a light can be made "invisible"
    tl;dr it needs to stay deactivated by default. :(

    I also thought about trying to use AC's standard "add". I made a prefab of the flashlight, and added it. Unfortunately, I'm limited by the fact that even if I set its position as relative to the camera, or the player, the game object will always be added into the scene and never as a child of another gameobject. Which means that my flashlight basically flies, lol
  • A custom action that enables/disables light components would be simple enough to write: just copy the ActionVisibility script and work from there.  Tutorials on writing Actions can be found here.
  • edited December 2014
    I'm not a programmer but I copied (and modified) the one Chris made for the particleswitch... it worked great for lights, here if u need:

    using UnityEngine;
    using System.Collections;

    public class ParticleSwitchLight : MonoBehaviour
    {
    public bool enableOnStart = false;
    private void Awake ()
    {
    Switch (enableOnStart);
    }
    public void TurnOn ()
    {
    Switch (true);
    }
    public void TurnOff ()
    {
    Switch (false);
    }
    public void Interact ()
    {
    if (this.particleSystem)
    {
    this.particleSystem.Emit (this.particleSystem.maxParticles);
    }
    }
    private void Switch (bool turnOn)
    {
    if (GetComponent <Light>())
    {
    GetComponent <Light>().enabled = turnOn;
    }
    }
    }

  • hey, thanks a lot!

    It doesn't really solve my problem overall, but it's a start - besides it could very much turn useful for turning on and off a light. So, thanks a lot!  
    To use the "visibility" as alternative to activating\deactivating a game object, I'd still need a way to activate a collider at runtime, and to edit my flashlight script so that it stays disabled until the game object is visible.
  • Hi David,
    Sorry I'm rarely on this forum as I'm developing alone and was spending time learning iClone and how to use PSAI.
    Have a look into how easy it is to change tags with AC. If it is relatively simple all you need to do for invisible weapons is to set up the collision matrix so that colliders with one tag do not effect colliders with another tag. Then when you switch over from invisible to visible weapons change the weapon collider tag. This could cause problems  if a player does it right next to a wall but you have to judge the best way to handle that. Possibly look into the collision layer and tagging systems as the basic functionality of Unity may answer some of your problems, and AC makes effective use of the underlying framework, plus some actions are very easy to create oneself if there is a similar action in AC to begin with.
  • edited December 2014
    No worries, absolutely !

    And thanks a lot for your answer again, it's an interesting suggestion I hadn't considered. 

    The problem, is that I am a terrible coder so right now I wouldn't be capable to switch the collision matrix at runtime - I'd also need to access AC's script I guess so that I can tell the code to run "when the weapon is visible". (when X is visible -> make the change)
    Also, there is indeed the problem that you mentioned which could give weird consequences.

    In a way, it could work with a lot of work - currently I have only few things that are tagged as, generally, everything can collide with everything in my game- but it seems a bit like dancing around a problem which I wonder if it shouldn't be easier to solve, which is activating game objects at runtime. I just need to find a way to learn to code it myself via script, searching tutorials and so on or asking a friend, and then integrating it with AC 

    ChrisIceBox  can I ask you something hopefully simple? Can you point me where should I look in the source code to access the part that currently is used in the "Use" of the "Standard interactions" ? So that I could still make my script work when an icon is clicked on the inventory despite not using an AC Action.

    edit: now that I think about this, I still haven't tried using Unity's new GUI but could this actually come in handy for my problem?
  • Hard to say. It's still not 100% clear what the problem is, and why assetlist are a must in all circumstances. If the player and the GUI start in-scene then an actionlist asset is not needed and the activate/deactivate actions will work as required.

    Again, the solution is all dependant on what you are actually doing and why you are doing it that way and what is behind the design choices.

    Why, for example, has the inventory to be persistent in all scenes? and needs importing at runtime.

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.