Search Unity

Adventure Game Q&A

Discussion in 'Community Learning & Teaching' started by Adam-Buckner, Dec 21, 2016.

  1. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    2,879
    Hi @Adam-Buckner!

    I'm working on this project right now. I went on the learn page and something is missing: nowhere are the names of the two guys on the video mentioned! I think the man on the right is a "James" and the one on the left is you but how can we thank them if we do not know who they are? ;)

    In fact, if I recall correctly, very few projects are attributed.
     
  2. JamesB

    JamesB

    Unity Technologies

    Joined:
    Feb 21, 2012
    Posts:
    112
    @CrazyCGChick85
    So from the looks of your code I've noticed a couple of things that are up:
    The OnAnimatorMove function sets a Vector3 variable and then immediately overwrites it. Also that variable is never used. Not sure exactly what's going on there. It should be overriding the root motion of the character.
    The click not working on the red box leads me to believe that the red box's collider is offset from its visual position.
    The character moving to the wrong spot makes me think that either it has an offset from its root position or the interaction location is where the character ends up. Also, I don't know what the nav mesh you are using looks like so there could be a problem there.

    I hope that helps you narrow down what could be going wrong.

    @AnneSchmidt
    Hello there, the people involved in this project were:
    Adam Buckner - presenter/trainer (bearded American man in the videos)
    Peet Lee - Art/Animation
    Stefano Guglielmana - Art/Animation
    Aurore Dimopoulos or Will Goldstone - Producer (sorry guys I don't remember who was boss at that point!)
    James Bouckley - developer/presenter/trainer/me

    Unfortunately Adam no longer works at Unity but he might still be around the forums, who knows!
     
    CrazyCGChick85 and APSchmidt like this.
  3. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    2,879
    Thank you!

    I wish the best to Adam. :)
     
    Last edited: Oct 28, 2018
  4. LordDarkenon

    LordDarkenon

    Joined:
    Sep 26, 2017
    Posts:
    4
    Hi - downloaded Phase 5, but the InteractableEditor script is missing from the download bundle. Could you please post a copy of the script here. Many thanks
     
  5. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    2,879
    The script is in project phase 1 "Assets\Scripts\Editor\Interaction". :)
     
    Last edited: Oct 28, 2018
  6. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    2,879
    About setting the "Locomotion" tag to the states Idle and Walking:
    • in the video, they enter the tag in each of them one after another but this can be done by multi-selecting the above mentioned animations in the state machine (avoiding possible misspelling).
    ;)

    Capture.JPG
     
    Last edited: Oct 24, 2018
  7. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    2,879
    I'm currently studying this project with Unity 2018.2.13f01. In the PlayerMovement script, the NavMeshAgent must be stopped and restarted; it appears that both

    Code (CSharp):
    1. NavMeshAgent.Stop ();
    2. NavMeshAgent.Resume ();
    are now deprecated.

    Code (CSharp):
    1. NavMeshAgent.IsStopped = true or false;
    must be used instead.

    New PlayerMovement script:
    Code (CSharp):
    1.     private void Stopping (out float speed)
    2.     {
    3.        agent.isStopped = true;           //instead of agent.Stop ();
    4.  
    5.        ...
    6.  
    7.     }
    8.  
    9.     private void Slowing (out float speed, float distanceToDestination)
    10.     {
    11.         agent.isStopped = true;           //instead of agent.Stop ();
    12.  
    13.         ...
    14.  
    15.     }
    16.  
    17. ...
    18.  
    19.     public void OnGroundClick (BaseEventData data)
    20.     {
    21.         ...
    22.  
    23.         agent.isStopped = false;            //instead of agent.Resume ():
    24.  
    25.      
    26. public void OnInteractableClick (Interactable interactable)
    27.    {
    28.        ...
    29.  
    30.        agent.isStopped = false;            //instead of agent.Resume ():
    31.     }
     
    Last edited: Oct 23, 2018
  8. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    2,879
    @James In fact, it is in all the projects, except the one in which we are supposed to work on it. The problem is that it is the full script that is in the other phases of the project, the places we are supposed to write are already written. :oops:

    Here is the script as it should be in the phase 5 of the project:
     

    Attached Files:

    Last edited: Oct 28, 2018
  9. CrazyCGChick85

    CrazyCGChick85

    Joined:
    Aug 30, 2018
    Posts:
    19
    Thanks. I thought the OnAnimatorMove was overriding but if I remove it it the character stops working. I moved the interaction location point and it did affect where the character collected the object so I think it's a combination of all 3. Now I just need to work out how to fix it all :D

    Again thanks for your help
     
  10. CrazyCGChick85

    CrazyCGChick85

    Joined:
    Aug 30, 2018
    Posts:
    19
    Update: It worked. I turned off the OnAnimatorMove and after some tinkering and help from my husband I turned the agent.isStopped to false instead of true in OnInteractableClick. However the character is not rotating to face the object when collecting but stays looking in the direction it was travelling in :D Back to research. Thanks again
     
  11. kearnsj2643

    kearnsj2643

    Joined:
    Dec 10, 2018
    Posts:
    1
    Hello, I am stuck on Phase 2 which is the third video in the game. How exactly does the player move through the door in the security room and into the market? It appears to show no code or way that it was done in the video. Any help would greatly appreciated.
     
  12. JamesB

    JamesB

    Unity Technologies

    Joined:
    Feb 21, 2012
    Posts:
    112
    @kearnsj2643 The Adventure Game training series is part of a training day. All of the content was filmed on one day where the audience goes through the content as we do. For this particular training day we tried something slightly different. Each phase uses a separate project and treats the attendee as though they are doing a specific job towards making a full game. As it turned out, this was terrifically well received on the day but has been a nightmare for us to keep up to date! Anyway, digressions aside, Phase 2 is to do with the inventory. The phase assumes the rest of the game is being made by someone else and that we only need to make the inventory. For information on transitioning between scenes see phases 3, 4 and 5. The parts of the game made in these phases put together allow the character to change scenes.
     
    APSchmidt likes this.
  13. PSchwilden

    PSchwilden

    Joined:
    Dec 9, 2016
    Posts:
    2
    Hello @JamesB!

    I have followed the tutorial (very well done by the way!) and wanted to extend on that, but I find myself with a problem I really can't get my head around, so I hope you can maybe help me.

    My modifications were mostly on two parts. The first one was creating conditions that could hold a script (like the reactions) so I would be able to check on more complicated conditions. The second one was integrating the reaction collection in the condition collection. The idea was that I didn't want to have to look for the reaction on another object. I ended up with something looking like this.

    upload_2018-12-15_16-29-46.png

    However, on the reaction collection part of the editor I am unable to open the reaction foldout or change the reaction selected in the popup.

    More specifically, after having done some debugging, I see that the values for the foldout bool (showReaction) or the popup selection int (selectedIndex) are set back to default just after I clicked. Debugging tells me that when I click, showReaction is equal to true but on the next OnInspectorGUI() it gets back to false.

    On the other side, if I show the reaction collection directly (so not contained in a condition collection). it works perfectly. So I'm guessing it's the condition collection that isn't able to serialize the changes it created on the reaction collection.
    I have been looking all over the internet for a beginning of hint, but I can't find anything.

    I'm attaching the modified scripts I have.

    Thank you in advance!
     

    Attached Files:

  14. JamesB

    JamesB

    Unity Technologies

    Joined:
    Feb 21, 2012
    Posts:
    112
    @PSchwilden

    Difficult to tell you exactly what's going wrong here but something I occasionally do when using Foldouts is use SerializedProperty.isExpanded instead of a stand alone bool. So in this case, find the SerializedProperty for the specific Reaction to be shown and use its isExpanded property. So this is sort of what happens behind the scenes in an inspector but not exactly. This work around will mean that the SerializedProperty will store whether or not the foldout is open or closed and so shouldn't depend on the editor.

    Hopefully this will help. If not, let me know I'll reply after Christmas.

    Happy Holidays to all!
     
  15. PSchwilden

    PSchwilden

    Joined:
    Dec 9, 2016
    Posts:
    2
    Hello @JamesB and happy holidays to you too!

    Your answer pointed me in the right direction and I now have it working!

    The issue was that the faulty editor was directly referenced as a ReactionCollectionEditor and not as a serialized property. I didn't notice but in the SubEditorSetup, the serialized properties of the subeditor are linked to the ones of the main editor.

    Code (CSharp):
    1.     private SerializedProperty reactionCollectionProperty;
    2.     private ReactionCollectionEditor reactionEditor;
    3.  
    4. //Later in code
    5.  
    6.     reactionEditor.reactionsProperty = reactionCollectionProperty;
    This is not the full code, but I'll attach the script if anyone else wants to check.

    Thank you for your help!
     

    Attached Files:

  16. nicmarxp

    nicmarxp

    Joined:
    Dec 3, 2017
    Posts:
    220
    @JamesB Thanks for a great tutorial, especially what can be done with editor scripts!

    I'm trying to expand to allow other condition types than just true/false. I've not come very far yet, but my first thougt would be to inherit the Condition scriptable object, but it feels wrong somehow, since I don't want to create a whole bunch of SO assets for each variable in the game. Or is that perhaps a good idea, to make it easier to save the game state later?

    I just find it easier to have them directly inside the same GameObject and not in the resources folder. This can maybe (probably?) be done with SO and editor scripts, so I can see the variables inside the editor, but I still find editor scripting hard :)

    I made something similar without scriptable objects, and I have an object called "Interaction Variables" on each interactable GameObject, to store "local" variables like "timesClicked" and I want to use this as a condition to run different reactions.

    Should I rewrite the Condition logic completely to allow for this, or could you suggest a way to do it?

    Thanks again!
     
  17. JamesB

    JamesB

    Unity Technologies

    Joined:
    Feb 21, 2012
    Posts:
    112
    @nicmarxp Thanks for the kind words about the tutorial, I'm glad you like it. Current Conditions should work with what it sounds like you are planning with some relatively minor rewrites. You could have a variable for the number of clicks (for example) and then the satisfied field is just requiredClicks == actualClicks. I'm a little confused about what you mean when talking about SO assets. To clarify, ScriptableObjects are not necessarily assets, they exist the same as other objects in memory and can be part of a scene instead of an asset. This is generally less common as the Hierarchy and Scene views show only GameObjects. The way this tutorial works is to create ScriptableObjects in the scene that are then referenced by MonoBehaviours and their fields are then shown in the Inspector using some editor scripts. One piece of advise I have for you when dealing with ScriptableObjects in the scene is to make sure you are careful to keep track of them and their lifecycle - if you lose references to them, then the scene will still reference them so they will not be picked up by the garbage collector.

    Sorry if that's a bit of a ramble, I hope it helps.
     
  18. nicmarxp

    nicmarxp

    Joined:
    Dec 3, 2017
    Posts:
    220
    Hi @JamesB thanks for replying so quickly, I'm still new to SO's so sorry if I talk about them incorrectly.

    I'm trying to expand on the Conditions, to create different kinds of conditions, for example:
    - ItemCondition (Does an item exist in the inventory)
    - StateCondition (GeneratorStarted or PanicButtonClickedTimes, pretty much like your conditions)
    - PlayerCondition (Choose a property from the player class, like health, and compare it)

    So basically Condition is the parent class, and the above are child classes, that set the "satisfied" based on different things. But I don't fully understand if I should be using scriptable objects, and/or if I just store them inside the ConditionCollection.

    Things like ItemCondition and PlayerCondition just checks with the inventory, and doesn't seem to store any data, while StateCondition needs to look up against some global variable, which might be a SO or just a list of floats somewhere.

    The "AllConditions" asset confused me a bit, since in the project view, it has all the conditions as children.

    I love the modularity of this, but I'm trying to see the benefits of using ScriptableObjects.

    Also I find the editor scripts amazing, but very complicated, and a lot of code, making it hard for me to customize. I'm using Odin Inspector which seem to be able to do things like inline editor, which might make this possible, without custom editors, but I'm not sure yet.

    Thanks for the tip regarding garbage collector!
     
  19. JamesB

    JamesB

    Unity Technologies

    Joined:
    Feb 21, 2012
    Posts:
    112
    @nicmarxp Okay so the reason that AllConditions is an asset is because it's value persists across scene loads and unloads. If you *know* that all your conditions are going to be in the same scene as the interactables that test them then there's you can avoid having the asset. Having AllConditions as an asset does help with saving and loading if you want to add that, but only because the data is easily accessible.

    The reason the editor scripts are so complicated is because each generally an editor represents a single Unity Object - a MonoBehaviour. The editor comes with its own serialized object that has been set up and has a life cycle that matches the editor. However, in order to use the serialized object system, EVERY Unity Object must have it's own SerializedObject. I tried to show this (I'm not sure how successful I was) by having each ScriptableObject have its own editor which would of course have its own SerializedObject. There are a few neater ways to achieve this that I regret not using now. But I didn't think of them however many years ago this was so... oh well!
     
  20. nicmarxp

    nicmarxp

    Joined:
    Dec 3, 2017
    Posts:
    220
    @JamesB Ah thanks for the explanation. I'm impressed that you still reply after all these years... but I guess that means it's still pretty solid! :)

    I studied the editor scripts some more, and begin to understand them, and appreciated that you could use the default appearence of the scriptableobject, in those cases where you didn't need a custom editor.

    You wouldn't know of a simple way of sorting the Reactions inside a ReactionCollection? It seems a bit more complex since we're having subeditors. But I'm thinking I need some drag/drop operation, and reorder the items of the
    reactions array, and then redraw it.

    I've seen some editors that use up/down arrows, I guess that's easier than drag drop.

    I looked at https://bitbucket.org/rotorz/reorderable-list-editor-field-for-unity/src/master/ but I'm not sure if that's implementable with the subeditors. Here's what that looks like. I don't need to move between lists, just up/down within a list.

     
    Deadcow_ likes this.
  21. JamesB

    JamesB

    Unity Technologies

    Joined:
    Feb 21, 2012
    Posts:
    112
  22. nicmarxp

    nicmarxp

    Joined:
    Dec 3, 2017
    Posts:
    220
    Thanks @JamesB, I also just found this, which seem to do exactly that, but allowing to select what type of scriptable object to add. He didn't publish the code for what he calls a ScriptableObjectDrawer.


    I'll see what I can work out from that. :)
     
  23. marpe

    marpe

    Joined:
    Nov 17, 2014
    Posts:
    3
    Saw some people in this thread mentioning having problems with making prefabs out of interactables (which is why I first came here).

    I replaced the condition and reaction collections with UnityEvent in order to solve the issue. I'm guessing the polymorphism limitation mentioned here was the problem.
     
  24. chris0xcd

    chris0xcd

    Joined:
    Sep 17, 2019
    Posts:
    3
    Hi @JamesB,
    I've tried working through Phase 1 in Unity 2018.4 but cannot select OnGroundClick in the "Pointer Click" Event Trigger.
    Trying the same thing in Unity 2017 works as expected.

    If I remove the BaseEventData parameter from OnGroundClick it does show up, but of course then I can't get the PointerEventData.

    Are BaseEventData parameters no longer available in Unity 2018 and if so how do I get to pointerCurrentRaycast or am I missing something else?

    Btw. the Pointer Click header actually shows the BaseEventData parameter in 2017 but shows now parameter in 2018.
    2017:
    2017.PNG
    2018:
    2018.PNG

    Thanks in advance
     
  25. JamesB

    JamesB

    Unity Technologies

    Joined:
    Feb 21, 2012
    Posts:
    112
    Hello @chris0xcd
    I haven't played with the event system since this tutorial so I'm unsure of how things have changed. When the original tutorial came out I believe we used BaseEventData to get around a bug. Try using a PointerEventData parameter and see if it then appears.
     
  26. chris0xcd

    chris0xcd

    Joined:
    Sep 17, 2019
    Posts:
    3
    Hi @JamesB, thanks for the quick reply!

    Unfortunately using PointerEventData doesn't seem to work either. So far I was unable to find anything in the Unity documentation or any tutorials for 2018+ that use the Event System in this way. I'm still quite new to Unity so I might just be using the wrong search terms. Any pointers on where I might find more information would be highly appreciated.

    Btw. if anyone else is stuck at this and just wants to get on with it: As a workaround I removed the BaseEventData parameter and manually perform the raycast. (The Camera needs to be tagged as MainCamera in order for Camera.main to be set)

    Code (CSharp):
    1.  
    2.     public void OnGroundClick()
    3.     {
    4.         if (!handleInput)
    5.         {
    6.             return;
    7.         }
    8.  
    9.         Ray myRay = Camera.main.ScreenPointToRay(Input.mousePosition);
    10.         RaycastHit raycastHit;
    11.        
    12.         if (!Physics.Raycast(myRay, out raycastHit, Mathf.Infinity, Physics.AllLayers))
    13.         {
    14.             return;
    15.         }
    16.  
    17.         currentInteractable = null;
    18.  
    19.         NavMeshHit hit;
    20.        
    21.         if (NavMesh.SamplePosition(raycastHit.point, out hit, navMeshSampleDistance, NavMesh.AllAreas)) // now uses raycastHit.point instead of pointerData.pointerCurrentRaycast.worldPosition
    22.         {
    23.             destinationPosition = hit.position;
    24.         }
    25.         else
    26.         {
    27.             destinationPosition = raycastHit.point;
    28.         }
    29.  
    30.         agent.SetDestination(destinationPosition);
    31.         agent.Resume();
    32.     }
    33.  
     
  27. JamesB

    JamesB

    Unity Technologies

    Joined:
    Feb 21, 2012
    Posts:
    112
  28. chris0xcd

    chris0xcd

    Joined:
    Sep 17, 2019
    Posts:
    3
  29. pbrito_unity

    pbrito_unity

    Joined:
    Mar 30, 2018
    Posts:
    18
    I specify a individual delegate as suggested in EventTrigger.cs.
    Now I can use PointerEventData :

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.EventSystems;
    3.  
    4.  
    5. public class EventTriggerDelegateExample : MonoBehaviour
    6. {
    7.     void Start()
    8.     {
    9.         EventTrigger trigger = GetComponent<EventTrigger>();
    10.         EventTrigger.Entry entry = new EventTrigger.Entry();
    11.         entry.eventID = EventTriggerType.PointerDown;
    12.         entry.callback.AddListener((data) => { OnPointerDownDelegate((PointerEventData)data); });
    13.         trigger.triggers.Add(entry);
    14.     }
    15.  
    16.     public void OnPointerDownDelegate(PointerEventData data)
    17.     {
    18.         Debug.Log("OnPointerDownDelegate called.");
    19.     }
    20. }
    You still need to add the EventTrigger component for this to work,
     
  30. Donlod

    Donlod

    Joined:
    Mar 14, 2016
    Posts:
    3
    Hello,
    I encountered a problem with the ReactionCollection component as soon as you apply changes made to this component to the prefab.
    For example when applying all overrides of the "CoinInteractable" gameobject to the prefab.
    If you then add a new gameobject using that prefab all ReactionCollection components that were previously updated by applying are broken.

    This is the error I get

    NullReferenceException: Object reference not set to an instance of an object
    ReactionCollectionEditor.SubEditorSetup (ReactionEditor editor) (at Assets/Scripts/Editor/Interaction/ReactionCollectionEditor.cs:60)
    EditorWithSubEditors`2[TEditor,TTarget].CheckAndCreateSubEditors (TTarget[] subEditorTargets) (at Assets/Scripts/Editor/Abstracts/EditorWithSubEditors.cs:33)
    ReactionCollectionEditor.OnEnable () (at Assets/Scripts/Editor/Interaction/ReactionCollectionEditor.cs:42)

    When debugging the editor code it looks like the "editor" parameter is null. Usually it contains a subeditor. The subeditors are extracted and created from the "reactions" array of the ReactionCollection script. But in this case all the elements of the array are null. The array length is correct.

    Any ideas how to fix this?