Adventure Game Q&A

This is the official thread for discussion, issues and Q&A for the Adventure Game project

Please use this thread if you have any questions, issues or feedback on this project.

Adventure Game is a learning project on our Learn Site:

Originally shot at Unite LA 2016 Training day, the Adventure Game tutorial will teach you how to make a point and click adventure game. It is aimed at intermediate learners.

When discussing, asking for help or reporting an issue, please tell us which phase you are referring to.

Phase 1 teaches you how to build a click to move animated character using the EventSystem, NavMesh, Animator and Prefabs.
Phase 2 teaches you how to build an inventory including building a UI and item management system for player inventory using Unityā€™s UI System and some editor scripting.
Phase 3 teaches you how to build an interaction system, focusing on conditions. We will create a system to check the current game state, discuss scripting patterns and use scriptable objects, generic classes, inheritance and extension methods.
Phase 4 continues teaching how to build an interaction system focusing on reactions. We will create a system to perform actions based on condition state using polymorphism, further editor scripting and discuss serialization.
Phase 5 continues teaching you how to build an interaction system, focusing on interactables. We will create a system to define what the player can interact with including interactable geometry, use the EventSystem and give an interaction system summary.
Phase 6 teaches you how to create a system to load scenes while preserving game state using the Scene Manager, ScriptableObjects as temporary runtime data storage, delegates and lambda expressions.

5 Likes

Thank you for this! I really enjoyed watching the series. :slight_smile:
I like that the learn site is featuring more and more content for intermediate/advanced users.

Is there a reason for choosing Editors and SubEditors as shown in phases 3 and 4 over PropertyDrawers?

In the video for making the Player prefab: phase 1b, when you playtest the character walking around for the first time (44:30) I get an error.
I get the ā€œSetDestination()/Resume() can only be called on an active agent that has been placed on a NavMeshā€ error and the character does not move.

Iā€™ve tried using more forgiving NavMesh settings, ensuring the NavAgent is touching the ground, checked through all the scripts , was sure to add in the UnityEngine.AI namespace since Iā€™m using 5.5 but Iā€™m still unsure of where Iā€™m going wrong.

Fantastic series, by the way! Loving the extra lengths you guys and gals went to on this training day.

Iā€™m just wondering whether Iā€™ve understood the workings of the following line in the PlayerMovement script in phase 1b), in the function Moving().

transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, turnSmoothing * Time.deltaTime);

If I read this correctly, then it doesnā€™t actually directly turn the player from the initial rotation to the desired rotation over a set amount of frames, but rather, for each frame, checks the current rotation, and then rotates the player a certain fraction of however much is left in order to reach the desired rotation. Said fraction is given by the actual value of turnSmoothing * Time.deltaTime.

So if, for instance, turnSmoothing is 15, and the framerate is 50Hz (which makes deltaTime 0.02), then for each frame the above line will turn the player 30% of the ā€œremainingā€ distance to the desired direction. Mathematically, the player will actually never entirely reach the desired rotation, but rather close in on it exponentially (which means that for a computer working with floats, it will quite quickly become indistinguishable from the true desired direction).

Is this right, or have I minsunderstood what is going on here?

Yes, I think youā€™re right. This produces a rotation that starts off relatively fast and slows down as it reaches itā€™s target.

Ah, silly me. I had a reference to the player prefab instead of the player instance in the event trigger.

Iā€™m about halfway through Phase 1b where you first test the playerā€™s movement, I have a problem that I think is related to the Animator Controller and havenā€™t been able to troubleshoot it:

When ClickToMove is selected as the Animator Controller, the player takes one step into the room and then stops. Subsequent clicks rotate but donā€™t change her position.
When ā€˜Noneā€™ is selected is the Animator Controller, the player floats around the room in the starting posture.

Any advice on what Iā€™m missing? Thanks.

EDIT: Figured it out, I had the ā€˜greater thanā€™ and ā€˜less thanā€™ mixed up for player idle and walking states.

Hello there!

TL;DR No functional reason. Editors are easier to teach and EditorWithSubEditors included some C# features I wanted to teach.

There are some reasons why I chose to use Editors and Sub-Editors over PropertyDrawers, though nothing so substantial as ā€œEditors are just better!ā€ or anything like that! Using PropertyDrawers can be tricky when youā€™re dealing with multi-line inspectors since you have to calculate the size required in advance. Combine that with having sub-PropertyDrawers and it gets more tricky. None of this is impossible of course, but it is difficult to teach. Using Editors also gave me the chance to introduce abstracts and generic classes which is something I find incredibly useful and something that I donā€™t believe weā€™ve covered much before.

Hope that helps. Glad you liked the training!

1 Like

Hi,

Iā€™m on phase 3/6. The PDF tells me to click the ā€˜Add Collectionā€™ button of the ā€˜Intractableā€™ component, but I receive 4 errors in the console when I do this. Any assistance would be appreciated. I havenā€™t had a chance to break down the code. I was going to do that after finishing up the PDF. Iā€™m using Unity 5.41 if that matters. This was after downloading phase 3/6 install. I then downloaded phase 4/6 and it worked without any issues. I would just like to know for troubleshooting purposes on my own project. Error message 01 may not be relevant to the problem. I was trying out various things.

ERROR MSG 01:
NullReferenceException: Object reference not set to an instance of an object
PlayerMovement.Start () (at Assets/Scripts/MonoBehaviours/Player/PlayerMovement.cs:44)

ERROR MSG 02:
NullReferenceException: Object reference not set to an instance of an object
InteractableEditor.SubEditorSetup (.ConditionCollectionEditor editor) (at Assets/Scripts/Editor/Interaction/InteractableEditor.cs:39)
EditorWithSubEditors`2[TEditor,TTarget].CheckAndCreateSubEditors (.TTarget[ ] subEditorTargets) (at Assets/Scripts/Editor/Abstracts/EditorWithSubEditors.cs:23)
InteractableEditor.OnInspectorGUI () (at Assets/Scripts/Editor/Interaction/InteractableEditor.cs:47)
UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1235)
UnityEditor.DockArea:OnGUI()

ERROR MSG 03:
ArgumentException: Getting control 0ā€™s position in a group with only 0 controls when doing Repaint
Aborting
UnityEngine.GUILayoutGroup.GetNext () (at /Users/builduser/buildslave/unity/build/Runtime/IMGUI/Managed/GUILayoutUtility.cs:665)
UnityEngine.GUILayoutUtility.DoGetRect (Single minWidth, Single maxWidth, Single minHeight, Single maxHeight, UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[ ] options) (at /Users/builduser/buildslave/unity/build/Runtime/IMGUI/Managed/GUILayoutUtility.cs:410)
UnityEngine.GUILayoutUtility.GetRect (Single minWidth, Single maxWidth, Single minHeight, Single maxHeight, UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[ ] options) (at /Users/builduser/buildslave/unity/build/Runtime/IMGUI/Managed/GUILayoutUtility.cs:399)
UnityEditor.EditorGUILayout.GetControlRect (Boolean hasLabel, Single height, UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[ ] options) (at /Users/builduser/buildslave/unity/build/Editor/Mono/EditorGUI.cs:7316)
UnityEditor.EditorGUILayout.GetControlRect (Boolean hasLabel, Single height, UnityEngine.GUILayoutOption[ ] options) (at /Users/builduser/buildslave/unity/build/Editor/Mono/EditorGUI.cs:7311)
UnityEditor.PropertyHandler.OnGUILayout (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, Boolean includeChildren, UnityEngine.GUILayoutOption[ ] options) (at /Users/builduser/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyHandler.cs:193)
UnityEditor.EditorGUILayout.PropertyField (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, Boolean includeChildren, UnityEngine.GUILayoutOption[ ] options) (at /Users/builduser/buildslave/unity/build/Editor/Mono/EditorGUI.cs:7296)
UnityEditor.EditorGUILayout.PropertyField (UnityEditor.SerializedProperty property, UnityEngine.GUILayoutOption[ ] options) (at /Users/builduser/buildslave/unity/build/Editor/Mono/EditorGUI.cs:7278)
InteractableEditor.OnInspectorGUI () (at Assets/Scripts/Editor/Interaction/InteractableEditor.cs:49)
UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1235)
UnityEditor.DockArea:OnGUI()

ERROR MSG 04:
NullReferenceException: Object reference not set to an instance of an object
InteractableEditor.OnInspectorGUI () (at Assets/Scripts/Editor/Interaction/InteractableEditor.cs:53)
UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1235)
UnityEditor.DockArea:OnGUI()

@Tris73 Hello there, I can tell you what caused the error but not how it came about Iā€™m afraid. Errors 2, 3 and 4 are all caused by the same thing. SubEditorSetup is called whenever new subeditors are required by an editor that has subeditors. Specifically, the editor that is passed to the function is created using the CreateEditor function and can be null (as it is in your error) under the following circumstances:

  • the target for editor creation was null
  • there was a type mismatch between the created editor and the generic type it is cast to in EditorWithSubEditors
  • there was no potential editor to create for the given target
    Of these the most likely is that the target created was null so when looking into how it happened I suggest starting your search there.

Have you edited the PlayerMovement script? Because according to my version there is no code to null ref on the line specified by your error code.

Sorry I couldnā€™t be more help.

P.S. On a semi-related note, I recommend you use the PDFs for guidance and use the videos to follow the tutorial.

James, thank you very much for the quick response and helping me to narrow down my search parameters. Iā€™ll take a look and post what I find.

@JamesB Thanks. You were right about the target being null. I must have looked over the ConditionCollectionEditor script hundreds of times and missed the one line. I found it with a Diff tool :rage: So much for attention to detail. Well, if nothing else, I have a better understanding of how the scripts interact. I left this line out:

conditionCollection = (ConditionCollection)target;

Thanks again. I can sleep peacefully now :slight_smile:

Sorry, can I ask a question?
In Phase 1, you used the ā€œagent.desiredVelocityā€ to set the speed, what is agent.desiredVelocity?
And what is the difference between agent.desiredVelocity and agent.speed?

hey everyone,
at phase 4 i have a bunch of questions.
basically about the Editor.CreateEditor(); .
my question is, when creating the condition collection, and condition sub editors (and i have used the same system for my own inventory too) (Inventory>Slots>Items){following this chain}. it appeared to me that, i always get null after casting the newly created editor with that function as {TEditor}. (EditorWithsubEditors Script)
the fix to that, was using the second overload form of the Editor.CreateEditor(Object,TypeOf(TEditor)); after using it in this form, it worked perfectly.

however, the issue i have faced when using this form, is simply because, this overloaded version of the function, is unable to create the Abstract Editor which is (ReactionEditor).
this issue was solved by using the first overloaded form of the function which is Editor.CreateEditor(Object); where i do not specify the type.

can any one please elaborate and give some detailed explanation on this issue? i mean, sure it worked, but i do not really deeply understand what is going on. perhaps i do believe the key thing lies within the Editor.CreateEditor function, but the manual is wellā€¦ does not say much really.

would be really glad if someone helps, thanks guysā€¦

Edit: iā€™d just like to say, when i download the package it works fine without any changes, but what i am doing is trying to create these systems from scratch and put them in my game. and so, while im doing that, this is the trouble i came across.

so do i just make it a rule inside my mind? when creating abstract editor that needs to be overridden i use the first form, other wise i use the second form?.

an explanation would be really appreciated. thanks in advance again everyone.

Edit2: after this long post iā€™d like to say, that, if i want to use the first form i must put an attribute on the top of the class, but if i want to use the second form, i can simply not put the attribute.

so i guess it was solved :smile:

Hi everyone, i try to remake the sound of this demo with Fmod, for now all works, but in the console, the fmod send me a message about some dlyb that in the other demos not appear. Are there some incompatiblity?

thanks

Hi all loved the series
Just wanted to ask how would I do proper saving? so you can close game and carry on later
Iā€™m not too good at coding so please go easy on me :stuck_out_tongue:

Thanks :smile:

1 Like

Hi. I have started working on Phase 1 with Unity 5.5. Today I updated to Unity 5.6 and got some issues.

When I try to edit the ReactionCollection of some interactables, the unity console shows me some errors like this:

NullReferenceException: Object reference not set to an instance of an object
ReactionCollectionEditor.OnInspectorGUI () (at Assets/Scripts/Editor/Interaction/ReactionCollectionEditor.cs:57)
UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1229)
UnityEditor.DockArea:OnGUI()

I think that this is some compatibility issue. But I donā€™t really know. I am just a beginner.

Other problem that I am facing, is with the pathfinding system. Every time I click on the ground, the character takes from 5 to 10 seconds to start moving towards the destination. I canā€™t figure out what is wrong. I did every step like the videos. This problem was already present with unity 5.5.

I hope that you guys can help me. I am very excited to learn everything I can from this tutorial so I can take one more step in my goal of being a game developer.

Thanks in advance. =]

I would suggest that you double check the steps as I donā€™t recognize these errors as being an upgrade issue.

Perhaps @JamesB might know more.

@rasert Iā€™ve had a look into the code to see what could be causing your problems. The null reference you are reporting comes from having editors created for null objects. So in your case it seems like a null Reaction has been created somehow, then when the corresponding Editor is created, it is created as null as well. Iā€™m not sure how this could come about but my recommendation to try and fix it would be to reset the component. This should clear out all Reactions, null or otherwise. From there you should be able to start afresh and have no more null Reactions or Editors.

As for the Player taking a really long time to move anywhereā€¦ thatā€™s a really weird one. I honestly have no idea what could be causing that. My suggestion would be to Debug the code by attaching the code editor you are using to the Unity Editor. If youā€™re not familiar with how to do that, try adding Debug logs to the code to see what is being called when. Do this by adding lines like:

Debug.Log(ā€œOnGroundClick called.ā€);

When you have a few of these logs in the code, see when the various bits of code are being called by testing it. This should help determine where the delay is coming from.

Everytime I open the ā€œPersistentā€ scene, itā€™s marked with an asterisk and asks me if I want to save the changes when I try to open another scene, as if it has been edited (it wasnā€™t, just opening the scene leaves an asterisk). Anyone knows why is this happening? Is something like a corrupted asset or scene file causing this problem? Should I just save the scene and hope that will cause the problem to go away? I was changing the aspect ratio at one point, but I donā€™t believe such changes and saved in the file of the current scene.