Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Adventure Game Q&A

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

  1. DrGonzosGame

    DrGonzosGame

    Joined:
    May 1, 2017
    Posts:
    12
    In case anyone actually reads stuff in here - dropping the players Turn Smoothing value from 15 down to around 7 seemed to have fixed the issue.
     
    Malkalypse likes this.
  2. HristoMalakov

    HristoMalakov

    Joined:
    Aug 3, 2017
    Posts:
    15
    Greetings,

    In phase 1b, at minute 45, when I have to test my character movement, I cannot move at all. No rotation, no animation, nothing. I tried looking for answers to the most common problems, but nothing helped. I downloaded the completed version of the asset store and copy-pasted the code from the ready PlayerMovement into mine, but it didn't help either. I followed the video to the dot, I checked my parameters twice, but I never found the problem. Would you please help me with that?

    EDIT: I get the error

    There are no audio listeners in the scene. Please ensure there is always one audio listener in the scene
    0x00000001409897FB (Unity) StackWalker::GetCurrentCallstack
    0x000000014098CD5F (Unity) StackWalker::ShowCallstack
    0x0000000140D35030 (Unity) GetStacktrace
    0x0000000141079D56 (Unity) DebugStringToFile
    0x000000014107A52C (Unity) DebugStringToFile
    0x0000000140B9A7DC (Unity) AudioManager::ListenerCheck

    I dont know why, I remember I did the step where they set an Audio Listener and the lecturer explains why it's important to have one.


    Thank you in advance.

    EDIT: My mistake was that I imported all assets into the same project. Fixed it. No need for help.

    This is my code:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.EventSystems;
    5. using UnityEngine.AI;
    6.  
    7. public class PlayerMovement : MonoBehaviour
    8. {
    9.  
    10.     public Animator animator;
    11.     public NavMeshAgent agent;
    12.     public float inputHoldDelay = 0.5f;
    13.     public float turnSpeedThreshold = 0.5f;
    14.     public float speedDampTime = 0.1f;
    15.     public float slowingSpeed = 0.175f;
    16.     public float turnSmoothing = 15f;
    17.  
    18.     private WaitForSeconds inputHoldWait;
    19.     private Vector3 destinationPosition;
    20.  
    21.     private const float stopDistanceProportion = 0.1f;
    22.     private const float navMeshSampleDistance = 4f;
    23.  
    24.     private readonly int hashSpeedPara = Animator.StringToHash("Speed");//?
    25.  
    26.     private void Start()
    27.     {
    28.         agent.updateRotation = false;// stops player when they are down for item
    29.  
    30.         //pause in between interactions
    31.         inputHoldWait = new WaitForSeconds(inputHoldDelay);
    32.  
    33.         //sets the starting position of the char
    34.         destinationPosition = transform.position;
    35.     }
    36.  
    37.     //moves the char
    38.     private void OnAnimatorMove()
    39.     {
    40.         agent.velocity = animator.deltaPosition / Time.deltaTime;
    41.  
    42.     }
    43.  
    44.     private void Update()
    45.     {
    46.         if (agent.pathPending)
    47.         {
    48.             return;
    49.         }
    50.  
    51.         float speed = agent.desiredVelocity.magnitude;
    52.  
    53.         if (agent.remainingDistance <= agent.stoppingDistance * stopDistanceProportion)
    54.         {
    55.             Stopping(out speed);
    56.         }
    57.  
    58.         else if (agent.remainingDistance <= agent.stoppingDistance)
    59.         {
    60.             Slowing(out speed, agent.remainingDistance);
    61.         }
    62.  
    63.         else if (speed > turnSpeedThreshold)
    64.         {
    65.             Moving();
    66.         }
    67.  
    68.         animator.SetFloat(hashSpeedPara, speed, speedDampTime, Time.deltaTime);
    69.     }
    70.  
    71.     private void Stopping(out float speed)//becauyse we are affecting the speed outside of the function
    72.     {
    73.         agent.isStopped = true;// original code: agent.Stop()
    74.         transform.position = destinationPosition;
    75.         speed = 0f;
    76.     }
    77.  
    78.     private void Slowing(out float speed, float distanceToDestination)
    79.     {
    80.         agent.isStopped = true;//
    81.         transform.position = Vector3.MoveTowards(transform.position, destinationPosition, slowingSpeed * Time.deltaTime);
    82.         float proportionalDistance = 1f - distanceToDestination / agent.stoppingDistance;
    83.         speed = Mathf.Lerp(slowingSpeed, 0, proportionalDistance);
    84.  
    85.     }
    86.  
    87.     //just sets the rotation
    88.     private void Moving()
    89.     {
    90.         Quaternion targetRotation = Quaternion.LookRotation(agent.desiredVelocity);
    91.         transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, turnSmoothing * Time.deltaTime);
    92.     }
    93.  
    94.     public void OnGroundClick(BaseEventData data)
    95.     {
    96.         PointerEventData pData = (PointerEventData)data;
    97.         NavMeshHit hit;
    98.  
    99.         //if we hit something, move there
    100.         if (NavMesh.SamplePosition
    101.             (pData.pointerCurrentRaycast.worldPosition, out hit, navMeshSampleDistance, NavMesh.AllAreas))
    102.         {
    103.             destinationPosition = hit.position;
    104.         }
    105.         //else find something nearby
    106.         else
    107.         {
    108.             destinationPosition = pData.pointerCurrentRaycast.worldPosition;
    109.         }
    110.         // and set us there
    111.         agent.SetDestination(destinationPosition);
    112.         agent.isStopped = false;
    113.     }
    114.  
    115. }
    116.  
     
    Last edited: Aug 14, 2017
  3. TheLapisFox

    TheLapisFox

    Joined:
    Feb 14, 2017
    Posts:
    3
    Noticed a few issues here.

    1. In all of the packages for this tutorial, agent.Stop() and agent.Resume() should be changed to agent.IsStopped = true/false (respectively) within the PlayerMovement.cs script;
    2. This one is the most damaging issue, the download for 5/6 is missing the Editor script InterableEditor.cs completely.

    While #1 is not a game stopper as Unity will still allow the Stop and Resume methods (at least until they are removed anyways), it is completely impossible to continue past 10:54 in the video without that script. Might want to have someone take a look and fix that package.
     
  4. Ins_Py

    Ins_Py

    Joined:
    Aug 21, 2017
    Posts:
    5
  5. Ins_Py

    Ins_Py

    Joined:
    Aug 21, 2017
    Posts:
    5
    Anyone ?
    I'm always stuck ...
     
  6. drhmiri

    drhmiri

    Joined:
    Jun 17, 2014
    Posts:
    72
    I imported the complete game, which should presumably work without modifications. Right?

    However, as I followed along the first two phases (The Player & The Player Continued) I realized there were a couple of tiny things that still needed to be done, though now when I run the game, I get the following three error messages, the first two referring to a missing SceneController, and the third one highlights the Player game object in the Hierarchy.

    UnityException: Scene Controller could not be found! Ensure that it exists in the Persistent scene.
    Saver.Awake () (at Assets/Scripts/MonoBehaviours/DataPersistence/Saver.cs

    NullReferenceException: Object reference not set to an instance of an object
    Saver.OnDisable () (at Assets/Scripts/MonoBehaviours/DataPersistence/Saver.cs

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

    There is a SceneController.cs script in the project. Where should I add that? Also, does anyone know what exactly it is that is null in the Player that I get the third error?
     
  7. NA_

    NA_

    Joined:
    Aug 20, 2017
    Posts:
    4
    @drhmiri : I had similar problems once. You shouldn't start with the complete project when you want to follow the steps presented in the videos. The complete project contains parts that are not there yet in the first phases (e.g. persistent scene). This means things are set up a bit differently in the videos.

    If you want to follow the steps, download the asset package for the specific phase and start with that.
     
    drhmiri likes this.
  8. NA_

    NA_

    Joined:
    Aug 20, 2017
    Posts:
    4
    I have a general question about the interactable system that is presented in this tutorial. I'm using it a bit differently for a FPS game and its basically working fine (I adapted the way events are triggered).

    However, I noticed that it is not possible to save complete interactables (including condition collections and reaction collections) as prefabs. This is not working in the Adventure tutorial either ! You can try out with any complete intereactable (e.g. GuardInteractable, make a prefab of it). There are errors because the conditionCollections and reactionCollections contain null objects. They turn to null objects when I make the prefab.

    This is a problem to me. It has to be possible to save the complex interactables that I set up, so that I easily recreate them if something goes wrong.

    Why is this not working? Is it possible to adjust the interactable system to get this working?

    (really hoping that someone still looks into this thread... )
     
  9. twilightZone

    twilightZone

    Joined:
    Oct 10, 2014
    Posts:
    28
    Hello all,
    Thanks a lot for this tutorial which is very interesting.
    I do not have any problem, but I have a question, for the video "phase 2 of 6 - the inventory" at 45:00 we have to grab, from the hierarchy panel, the four itemImage on the inventory script in the window inspector to populate item slot 0, element 0 to item slot 3 element 3. It works well. but If I have, for example an inventory with 40 boxes, I have to repeat the operation 40 times, it is not very easy.
    If I give a different name for each different ItemImage, for example ItemImage0 --> ItemImage3, is it possible to create a script that automatically, at startup, link the ItemImage in the inventory script ?
    Thanks a lot
     
    Last edited: Sep 26, 2017
  10. Leink

    Leink

    Joined:
    Oct 3, 2017
    Posts:
    1
    Hello Someone can help me I'm in phase 1b of the adventure tutorial I have a problem that when I click to make my character progress simply does not, does not move from the site, someone has this happened?, Use Unity 2017 .1.0p5
     
  11. Monsoonexe

    Monsoonexe

    Joined:
    Jan 18, 2017
    Posts:
    1
    I am experiencing this same issue. It doesn't look like it's an issue with my code, as it all appears to match. I'm scrutinizing the animator next to debug this issue.
     
  12. Ettrig

    Ettrig

    Joined:
    Sep 15, 2017
    Posts:
    5
    How do we create a Mesh that can be dragged into the Mesh Collider.

    In part 1a, at 19 minutes, a NavMesh is made (Baked).

    Later, at 27:20 minutes, a Mesh Collider component is placed on object SecurityRoom in scene SecurityRoom.

    A Mesh (SecurityRoomMeshCollider) is dragged into a field in this component. The tutorial does not show how such meshes are generated.

    It is very easy (at least for me) to get the impression that the baking at 19 minutes creates the mesh used with the Mesh Collider at about 28 minutes. But it is not. The mesh that is used at 28 minutes exists in the imported (base) material, in Assets/Models/SecurityRoomCollision.

    Creating such a Mesh is a necessary step when using the knowledge from this tutorial to build similar but different games.
     
    Last edited: Oct 28, 2017
  13. Ettrig

    Ettrig

    Joined:
    Sep 15, 2017
    Posts:
    5
    One way to handle this problem is to copy the code from the finished project. I know the finished project runs OK in 2017.1. If you are intent on finding the bug, you can make different mixes of your own code and the functioning code from Unity. Exchanging first half of the code, then a quarter, then an eightth, a surprisingly small number of test rounds will zoom in on the error. Maybe this advice is too obvious. But the question here seems to show that it is needed. Good luck!
     
  14. kubajs

    kubajs

    Joined:
    Apr 18, 2015
    Posts:
    49
    Hi guys, first of all thanks for this great tutorial! I really appreciate you presented us with the interactables, interaction and all the related pro production project mature techniques and stuff.

    One question:
    In PlayerMovement script in OnGroundClickMethod:
    I don't understand under what circumstances the else clause can be hit (I was unable to simulate such a case in my project):
    Code (CSharp):
    1.  else
    2.             _destinationPosition = pData.pointerCurrentRaycast.worldPosition;
    My understanding is the OnGroundClick is hit only in case user clicks on the NavMesh. So in this case I believe we should also have the NaMeshHit set (as we already hit the navmesh so we should have the hit position as well). Why do we need the else condition and if it is really needed, could you please explain me what I need to do to get to the "else" clause?

    Thanks a lot,
    Kubajs
     
  15. Ettrig

    Ettrig

    Joined:
    Sep 15, 2017
    Posts:
    5
     
  16. Ettrig

    Ettrig

    Joined:
    Sep 15, 2017
    Posts:
    5
    This relates to my question above. I had the same incorrect understanding of how it works. In my view, the tutorial is misleading on this aspect. The OnGroundClick event is NOT (formally) related to the NavMesh. The event that triggers OnGroundClick is related to a Mesh that is referenced by the Mesh Collider. Mesh and NavMesh are different data types. but I suspect that the Mesh is a kind of translation of the NavMesh. I would like to learn how to make such a translation. See my question above.

    To see this, go to scene SecurityRoom and look at the object SecurityRoom in the Inspector. It has a component Event Trigger that calls the OnGroundClick function (method). I strongly suspect that the Event Trigger is triggered by the component Mesh Collider on the the same object (SecurityRoom). I think the Unity documentation for Event Trigger should specify how it is activated. But it doesn't, as far as I can see. If you click on the field Mesh in component Mesh Collider (in Inspector) it will highlight the referenced Mesh.

    You can test this explanation by extending the NavMesh. For example, in scene SecurityRoom you can remove the coffeetable, magazines and chairs, and rebake the NavMesh in the Navigation window. The changes in the NavMesh can now be seen in the Navigation window. But you cannot walk to the new NavMesh area. This is because there is no collider there, so the click will not be registered.

    That is as far as I got in my investigations. But actually it does not answer your question. I think that for your objective, you need to do the opposite: Add some objects so that the NavMesh becomes smaller. (Remember to make the objects Static.) Clicking near such a new object should get you to the else clause. I would be interested in your findings.
     
  17. kubajs

    kubajs

    Joined:
    Apr 18, 2015
    Posts:
    49
    Thanks Ettrig! You were right. I was finally able to reproduce it.
    How to reproduce it in the demo scene:
    1. set navMeshSampleDistance to 0.1f (variable in PlayerMovement script)
    2. click to the navMeshCollider area but outside NavMesh (e.g. on the rightmost chair).
    I couldn't get to the else clause before since navMeshSampleDistance was originally set to 4f so the tolerance was 4 meters. Looks like the navMeshCollider haven't overlapped the navMesh so much.

    So yes, exactly: OnGroundClick is called whenever user clicks to the navMeshCollider.
    but NavMesh area can be smaller than the navMeshCollider, therefore we need the else check.
    MaxDistance parameter in NavMesh.SamplePosition sets the tolerance radius how far the clicked position can be outside the NavMesh border.
     
    Last edited: Oct 31, 2017
  18. descenderz

    descenderz

    Joined:
    Nov 9, 2017
    Posts:
    1
    I have updated to the new version a few days ago and beginning this project. It does not recognize the namespace provided by the speaker or the text that shows during the same time. I went ahead and completed it but the click to move script does not seem to register. Any suggestions? I'm not sure if the namespace is causing the problem or not.
     
  19. jf3ng

    jf3ng

    Joined:
    Nov 11, 2017
    Posts:
    1
    I'm also using Unity 2017.1.0f3, and am getting these errors. Has anyone figured out why the LostItemReaction.cs, etc files aren't finding the Inventory namespace?
     
  20. Ettrig

    Ettrig

    Joined:
    Sep 15, 2017
    Posts:
    5
    I use 2017.1.1. A suggested work-around is to copy the script from the final project.
     
  21. dylanfachoso

    dylanfachoso

    Joined:
    May 31, 2017
    Posts:
    1
    ¡Hi! i got some issues with the animator ( i suppose). When i'm playing i have a long wait between the idle state and moving state. I have to wait to the animator to finish the Idle animation to move arround, if i stop i cannot pass to the moving state without waiting the animation complete. Anyone know how can i fix this?
     
  22. TomHillsten

    TomHillsten

    Joined:
    Sep 17, 2017
    Posts:
    1
    1. I am using Unity 2017.2.0f3. I am having a lot of confusion on what scene should be open, when I download the corresponding download. Example Video 5 of 6, Interactables. The video starts with an empty scene named "Untitled" with a long listed of folders for the project. So do I open a new scene and then download part 5 from the asset store?

    The videos do not, in my opinion, setup the start of each video well. I was not there for the live show, Unity title for the top just states, TrainingDayPhase5,,,

    2. I too did not/still don't know how/why to have 2 scenes open at the same time.

    3. In MonoDevelop, when I try to print a script, it prints small parts of the script on each page over like 10 pages. How can I print the whole script on 1 or 2 pages as needed?

    4. Is it possible to 'color' parts of a script, to visually breakdown the script into parts to read it easier?

    Thank you for any help you can provide.
     
    Last edited: Nov 26, 2017
  23. tam007

    tam007

    Joined:
    May 11, 2016
    Posts:
    1
    I have made a UML Diagram about this game tutorial. Anyone please tell me I am right or wrong ? Thank you !
     

    Attached Files:

  24. b33son

    b33son

    Joined:
    Dec 8, 2017
    Posts:
    5
    I can't seem to download the starting files from the Asset Store. The other Tutorials like Tanks are listed, but this one is missing.
     
  25. AnneSchmidt

    AnneSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    917
  26. b33son

    b33son

    Joined:
    Dec 8, 2017
    Posts:
    5
    That's where I was trying to download it from. When I click on "Open in Unity", my Unity launch window will appear. My Projects On Disk will show. But nothing else happens. If I go to "New" there's no new asset listed for Adventure Game. If I click on the "Learn" tab, the Adventure Game Tutorial is not listed. (Although the other Tutorials are listed there.)
     
  27. AnneSchmidt

    AnneSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    917
    You must create the new project and then the download will begin.
     
  28. b33son

    b33son

    Joined:
    Dec 8, 2017
    Posts:
    5
    Perfect. Thank you that worked.

    In case anyone else was confused too. These were the steps.

    1. Create a new empty project in Unity Editor
    2. Went back to the Adventure Game Asset page in browser: https://www.assetstore.unity3d.com/en/#!/content/76216
    3. Click Link. Asset tab opens in Unity Editor to the Adventure Game
    4. Click "Download". Learn & enjoy.
     
  29. klausenlie

    klausenlie

    Joined:
    Oct 24, 2017
    Posts:
    1
    Hi.

    When I open phase 1 project, I don`t get anything in the hierarchy window. Is it suppose to be like that?
    Same with the sample project.
     
  30. kylerichardson

    kylerichardson

    Joined:
    Jan 5, 2018
    Posts:
    5
    PROBLEM/TLDR: "SetDestination" and "Resume" can only be called on an active agent that has been placed on a NavMesh.

    SOLVED/TLDR: For those who do the same thing as me... This was happening because I drug the Player PREFAB into the GameObject slot of the PointerClick event trigger... If you use the one that is actually in your scene everything works perfectly! User error!

    Hello, first I'd like to say that this is an excellent tutorial series! Unfortunately I am encountering an error that I have not been able to run down. I am currently at the end of 02. The Player(Continued) and have just finished applying PlayerMovement.OnInteractableClick and the PictureInteractable(Interactable) to the PictureInteractable Event Trigger Script: Pointer Click(BaseEventData).

    I run the game, movement and everything works fine until I click on the picture. When I do I get the following errors displayed in the comments, from this function.

    Code (CSharp):
    1.     public void OnInteractableClick(Interactable interactable) {
    2.         if (!handleInput) {
    3.             return;
    4.         }
    5.  
    6.         currentInteractable = interactable;
    7.         destinationPosition = currentInteractable.interactionLocation.position;
    8.  
    9.         // Error: "SetDestination" can only be called on an active agent that has been placed on a NavMesh
    10.         agent.SetDestination(destinationPosition);
    11.         // Error: "Resume" can only be called on an active agent that has been placed on a NavMesh
    12.         agent.isStopped = false;
    13.     }
    I am using Unity 2017.3.0f3 and have made the changes required for the version difference, and replaced deprecated methods as you can see by the use of agent.isStopped = false instead of agent.Resume();.

    Here is a screenshot of my bake settings under the Navigation panel:

    Screen Shot 2018-01-09 at 3.00.07 PM.png

    Here is a screenshot of the Inspector with my PictureInteractable selected:

    Screen Shot 2018-01-09 at 3.01.18 PM.png

    Here is a screenshot of the Inspector with my Player selected:

    Screen Shot 2018-01-09 at 3.03.22 PM.png

    I can provide any additional requested information. Any assistance would be greatly appreciated!
     
    Last edited: Jan 9, 2018
  31. rishavtandon

    rishavtandon

    Joined:
    Jan 22, 2018
    Posts:
    2
    I completed phase 2 of adventure game however after doing all the scripts i am unable to switch between scenes. the player does not go to the market scene.
     
  32. rishavtandon

    rishavtandon

    Joined:
    Jan 22, 2018
    Posts:
    2



    You need to wrap the navmesh agent.
     
  33. Malkalypse

    Malkalypse

    Joined:
    Jan 13, 2017
    Posts:
    8
    I tried testing Phase 2 after completing it, but I only seem to be able to hold one item in my inventory at a time. Attempts to pick up any additional objects result in the following error message:

    NullReferenceException: Object reference not set to an instance of an object
    Inventory.AddItem (.Item itemToAdd) (at Assets/Scripts/MonoBehaviours/Inventory/Inventory.cs:24)

    Any idea what might be causing this?

    ----

    EDIT: After checking again, I realized that I had failed to populate the Inventory script item slots with the item images from the Persistent Canvas inventory item slots.
     
    Last edited: Feb 4, 2018
  34. Hazneliel

    Hazneliel

    Joined:
    Nov 14, 2013
    Posts:
    117
    The character teleports to the destination at the very last part of it, this is I guess because they are setting the position = destination when it is reaching the destination. This looks very weird, the player sudently flickering to the destination.
    Anyway to improve this?
     
  35. Zuzukal

    Zuzukal

    Joined:
    Jan 23, 2018
    Posts:
    2
    Currently going through the Adventure Game tutorial and once I get to Phase 2 and upload the assets I am no longer able to move. Tried checking my code and it's accurate. During the import I received a notification saying changes have been made to the Security Room, I'm sure those changes are the problem but I don't know what yet.

    I am currently stuck, I've even deleted the original and started a new with all the assets imported initially and it showed as if I had already done the tutorial (or at least some). This is quite mind boggling to me and am looking for help regarding the issue with importing assets and the changes made.

    Until I figure it out I won't be attempting the Adventure Game tutorial. I really wanted to complete this tutorial but, oh well. Any advice or information is appreciated.

    Thank you
     
  36. Sebaschen

    Sebaschen

    Joined:
    Apr 13, 2017
    Posts:
    2
    Hi!
    I have already completed the whole tutorial and integrated the reactioncollection to my own project. It works perfectly until I started to work with procedural generation, for which I needed to store a whole "scene" as a prefab.

    (For clarification, this question would be related to phase 3 where you guys implemented the interaction and reaction system.)

    As I mentioned, I needed to save a whole scene to a prefab, but if I drag the prefab up into the hierarchy, all ReactionCollections lose their reactions (Scriptable Objects). You could reproduce this problem if you store PictureInteractable as a prefab, and then dragging it into any random scene. If you then click on DefaultReaction under the instance, you will lose all Reactions attached to it.

    Is there anyway we could make prefabs NOT lose these Reactions? I am working with procedural generated game where each room is stored as a prefab so I need this to work. If not, I would have to rely on scenes to store the Reactions, which has certain drawbacks compared to using just a prefab.

    I know this question might be beyond the scope of this discussion, but if you could provide a solution or even any clue I would be very grateful!
     
  37. JamesB

    JamesB

    Unity Technologies

    Joined:
    Feb 21, 2012
    Posts:
    88
    @KingofWhaWha The way these interactions were designed, they were never meant to exist outside of the scene. Currently they are objects saved in the scene and referenced by the scripts which display them. In order for them to be part of the prefab they would need to be saved to the project - probably as part of the prefab itself. However this is not a normal thing for the Unity editor to do and so you will have to do it yourself. I'm not sure if it's even possible to do specifically what you want but here are some links which might be helpful:
    https://docs.unity3d.com/ScriptReference/PrefabUtility.CreatePrefab.html
    https://docs.unity3d.com/ScriptReference/AssetDatabase.AddObjectToAsset.html
    As I say, I'm not sure it's even possible as I have never tried it myself. If it works, please let me know.
     
  38. Sebaschen

    Sebaschen

    Joined:
    Apr 13, 2017
    Posts:
    2
    Thanks for info @JamesB! Since I posted the answer I have shifted away from the aforementioned approach, but still I'm insterested in implementing it. If I ever come up with a solution I'll definitely let you know!
     
  39. therealdrayton

    therealdrayton

    Joined:
    Apr 21, 2018
    Posts:
    1
    If anyone is still having this issue, I found the problem. For some reason when the script was created and renamed to "Inventory" it did not change the class name. So the class name stayed as "public class NewBehaviourScript : MonoBehaviour". If you change "NewBehaviourScript" to "Inventory" it will get rid of the error.
     
  40. occulus1975

    occulus1975

    Joined:
    Jan 7, 2017
    Posts:
    3
    Running Unity 2018.1.0 of 2 here (I... guess... that's Unity 5?). I am working my way through the adventure tutorial set and am receiving the following warning:

    "Lighting data asset ‘LightingData’ is incompatible with the current Unity version. Please use Generate Lighting to rebuild the lighting data. Realtime Global Illumination cannot be used until the lighting data is rebuilt."

    Rebuilding the lighting leaves the scene dark and global illumination is thereafter absent from the scene. I can't seem to find a way to get it working again. Does anyone know what I should do? Is the lighting data just broken?

    I've tried going into the lighting panel and rebuilding the data but that actually removes realtme GI- it gets rid of the warning but GI seems to be completely gone after that.
     
  41. JamesB

    JamesB

    Unity Technologies

    Joined:
    Feb 21, 2012
    Posts:
    88
    Hello there @occulus1975. Unity version numbers go 4, 5, 2017, 2018 then next year there will be 2019. We've used this new numbering system because of our change to a subscription model. The Adventure Game was made in Unity 5 and some things are a little bit fuzzy with newer versions.

    In order to get lighting to work you need to use the same bake process we had to use for Unity 5. In the level gameobject hierarchies there should be an inactive gameobject called BakedLights. Activate this gameobject, bake the lighting, then deactivate the gameobject again.

    This was a workaround we had to use due to a problem with the system at the time we made this tutorial. Unfortunately its meant that the workaround has to be used for all subsequent versions. Sorry about that!
     
  42. occulus1975

    occulus1975

    Joined:
    Jan 7, 2017
    Posts:
    3
    That did the trick. Thanks!
     
  43. CrazyCGChick85

    CrazyCGChick85

    Joined:
    Aug 30, 2018
    Posts:
    13
    Hi, I hope someone can help.

    I am currently on Phase 4 - Reactions. I have completed the video and followed everything. However, my text reaction is not working. Not only is the inspector for reaction not the same as the video, the text won't save and I keep getting errors like this (27 according to the console):

    "NullReferenceException: Object reference not set to an instance of an object
    UnityEditor.PropertyHandler.OnGUILayout (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, Boolean includeChildren, UnityEngine.GUILayoutOption[] options) (at C:/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyHandler.cs:203)
    UnityEditor.EditorGUILayout.PropertyField (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, Boolean includeChildren, UnityEngine.GUILayoutOption[] options) (at C:/buildslave/unity/build/Editor/Mono/EditorGUI.cs:8782)
    UnityEditor.EditorGUILayout.PropertyField (UnityEditor.SerializedProperty property, UnityEngine.GUILayoutOption[] options) (at C:/buildslave/unity/build/Editor/Mono/EditorGUI.cs:8766)
    TextReactionEditor.DrawReaction () (at Assets/Scripts/Editor/Interaction/ReactionEditors/TextReactionEditor.cs:34)
    ReactionEditor.OnInspectorGUI () (at Assets/Scripts/Editor/Interaction/ReactionEditors/ReactionEditor.cs:46)
    ReactionCollectionEditor.OnInspectorGUI () (at Assets/Scripts/Editor/Interaction/ReactionCollectionEditor.cs:38)
    UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor[] editors, Int32 editorIndex, Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1374)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)"

    I have even copied the script from the tutorial that is available. Can some help explain to me why this is saying so many instances don't exist? Thanks :)
     
  44. JamesB

    JamesB

    Unity Technologies

    Joined:
    Feb 21, 2012
    Posts:
    88
    @CrazyCGChick85 Very difficult to debug from this information but I have a few clues that can help you: The stack trace you posted has a null ref which goes through line 34 of TextReactionEditor. Somewhere on this line something is null when it's not expected to be. However, looking here: https://unity3d.com/learn/tutorials/projects/adventure-game-tutorial/reactions?playlist=44381 TextReactionEditor only seems to have 33 lines. Something is either wrong with the stack trace (which is going to make this impossible to track down) or the copy of TextReactionEditor that you have doesn't match the one from the website. Can you let us know what is on line 34 of your TextReactionEditor please?
     
  45. CrazyCGChick85

    CrazyCGChick85

    Joined:
    Aug 30, 2018
    Posts:
    13
    Hi James, thanks for the response.

    I added extra space between my lines, i'm learning so I am keeping some space for notes etc. This is what I have on line 34
    Code (CSharp):
    1. EditorGUILayout.PropertyField(textColorProperty);
    This is the entire code that I have from the TextReactionEditor
    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3.  
    4. [CustomEditor(typeof(TextReaction))]
    5. public class TextReactionEditor : ReactionEditor
    6. {
    7.     private SerializedProperty messageProperty;
    8.     private SerializedProperty textColorProperty;
    9.     private SerializedProperty delayProperty;
    10.  
    11.  
    12.     private const float messageGUILines = 3f;
    13.     private const float areaWidthOffset = 19f;
    14.     private const string textReactionPropMessageName = "message";
    15.     private const string textReactionPropTextColorName = "textColor";
    16.     private const string textReactionPropDelayName = "delay";
    17.  
    18.  
    19.     protected override void Init()
    20.     {
    21.         messageProperty = serializedObject.FindProperty(textReactionPropMessageName);
    22.         textColorProperty = serializedObject.FindProperty(textReactionPropTextColorName);
    23.         delayProperty = serializedObject.FindProperty(textReactionPropDelayName);
    24.     }
    25.  
    26.  
    27.     protected override void DrawReaction()
    28.     {
    29.         EditorGUILayout.BeginHorizontal();
    30.         EditorGUILayout.LabelField("Message", GUILayout.Width(EditorGUIUtility.labelWidth - areaWidthOffset));
    31.         messageProperty.stringValue = EditorGUILayout.TextArea(messageProperty.stringValue, GUILayout.Height(EditorGUIUtility.singleLineHeight * messageGUILines));
    32.         EditorGUILayout.EndHorizontal();
    33.  
    34.         EditorGUILayout.PropertyField(textColorProperty);
    35.         EditorGUILayout.PropertyField(delayProperty);
    36.     }
    37.  
    38.  
    39.     protected override string GetFoldoutLabel()
    40.     {
    41.         return "Text Reaction";
    42.     }
    43. }
    44.  
    Thanks again for your help
     
  46. JamesB

    JamesB

    Unity Technologies

    Joined:
    Feb 21, 2012
    Posts:
    88
    @CrazyCGChick85 So it seems that your textColorProperty is null. Chances are this is because the serialized property wasn't found by name. This is done on line 22 of the above script. Since this is done using a constant string we can see that if this is the case, textColor doesn't match a serialized field in the TextReaction class. Please ensure that your TextReaction class as a public or serialized field that is called exactly textColor. Any slight change in spelling or casing will cause it to not be found. If they are the same then this becomes a significantly harder problem to track down.
     
  47. CrazyCGChick85

    CrazyCGChick85

    Joined:
    Aug 30, 2018
    Posts:
    13
    That was it. I used to British spelling of color in the TextReaction script. Can't believe I missed that. Feel stupid now LOL. But thanks so much for your help. :D
     
  48. CrazyCGChick85

    CrazyCGChick85

    Joined:
    Aug 30, 2018
    Posts:
    13
    I finished the tutorials which were great and learnt a lot. I am trying to create a similar game but a murder mystery, so I have been reusing scripts from this. I have a problem which I cannot resolve. When my character picks up / collects an object it is not at object location but slightly off to one side
    .


    I think it has something to do with the raycast because I tested it on a camera without the camera script and have the same issue. I have also move the object around and still same issue (and character not turning to look at object when picking up but one issue at a time)

    I am at a loss as to where in the script I need to fix this and how.
     
  49. JamesB

    JamesB

    Unity Technologies

    Joined:
    Feb 21, 2012
    Posts:
    88
    I'm sorry, I don't understand the details of your issue. In the video you posted, when are you clicking the mouse to make the character move? What scripts are on which objects in the scene? What is the root position of the objects that get clicked on?
     
  50. CrazyCGChick85

    CrazyCGChick85

    Joined:
    Aug 30, 2018
    Posts:
    13
    "when are you clicking the mouse to make the character move?"
    When I click on the red box to 'collect' it nothing happens. When i click slightly to the left of the box the then character moves to collect the box

    "What scripts are on which objects in the scene?"
    Player -
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.AI; //Needs to be added to be used with the events system
    5. using UnityEngine.EventSystems; //Needs to be added when an event system ia required
    6.  
    7. [RequireComponent(typeof(Animator))]
    8.  
    9. public class PlayerMovement : MonoBehaviour
    10. {
    11.     public Animator animator;
    12.     public NavMeshAgent agent;
    13.     public float inputHoldDelay = 0.5f;
    14.     public float turnSpeedThreashold = 0.5f;
    15.     public float speedDampTime = 0.1f;
    16.     public float slowingSpeed = 0.175f;
    17.     public float turnSmoothing = 15f;
    18.     public bool isStopped;
    19.  
    20.     private WaitForSeconds inputHoldWait;
    21.     private Vector3 destinationPosition;
    22.     private Interactable currentInteractable;
    23.     private bool handleInput = true;
    24.    
    25.  
    26.     private const float stopDistanceProportion = 0.1f;
    27.     private const float navMeshSampleDistance = 4f;
    28.  
    29.     private readonly int hashSpeedPara = Animator.StringToHash("Speed");
    30.     private readonly int hashLocomotionTag = Animator.StringToHash("Locomotion");
    31.  
    32.     private void Start()
    33.     {
    34.         agent.updateRotation = false; //Don't update mesh rtoation
    35.  
    36.         inputHoldWait = new WaitForSeconds(inputHoldDelay);
    37.  
    38.         destinationPosition = transform.position;
    39.  
    40.     }
    41.  
    42.     private void OnAnimatorMove()
    43.     {
    44.         //root motion contoller for imported player
    45.         Animator animator = GetComponent<Animator>();
    46.  
    47.         if (animator)
    48.         {
    49.             Vector3 newPosition = destinationPosition; //Does nothing but if removed it breaks everything
    50.             newPosition = animator.deltaPosition / Time.deltaTime;
    51.         }
    52.  
    53.     }
    54.  
    55.     private void Update()
    56.     {
    57.         RaycastHit hit;
    58.        
    59.         if (agent.pathPending)
    60.         {
    61.             return;
    62.         }
    63.  
    64.         float speed = agent.desiredVelocity.magnitude;
    65.  
    66.         if (agent.remainingDistance <= agent.stoppingDistance * stopDistanceProportion)
    67.         {
    68.             Stopping(out speed);
    69.         }
    70.  
    71.         else if (agent.remainingDistance <= agent.stoppingDistance)
    72.         {
    73.             Slowing(out speed, agent.remainingDistance);
    74.         }
    75.  
    76.         else if (speed > turnSpeedThreashold)
    77.         {
    78.             Moving();
    79.         }
    80.        animator.SetFloat(hashSpeedPara, speed, speedDampTime, Time.deltaTime);
    81.        
    82.     }
    83.  
    84.     private void Stopping(out float speed)
    85.     {
    86.         //If agent has stopped, it needs to stop and stay at new position
    87.         agent.isStopped = true; // replaces agent.Stop();
    88.        
    89.         transform.position = destinationPosition;
    90.         speed = 0f;
    91.  
    92.         if (currentInteractable)
    93.         {
    94.             transform.rotation = currentInteractable.interactionLocation.rotation;
    95.             currentInteractable.Interact();
    96.             currentInteractable = null;
    97.             StartCoroutine(WaitForInteraction());
    98.         }
    99.  
    100.     }
    101.  
    102.     private void Slowing(out float speed, float distanceToDestination)
    103.     {
    104.         agent.isStopped = true;
    105.         transform.position = Vector3.MoveTowards(transform.position, destinationPosition, slowingSpeed * Time.deltaTime);
    106.  
    107.         float proportionalDistance = 1f - distanceToDestination / agent.stoppingDistance;
    108.         speed = Mathf.Lerp(slowingSpeed, 0f, proportionalDistance);
    109.     }
    110.  
    111.     private void Moving()
    112.     {
    113.         Quaternion targetRotation = Quaternion.LookRotation(agent.desiredVelocity);
    114.         transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, turnSmoothing * Time.deltaTime);
    115.     }
    116.  
    117.     public void OnGroundClick(BaseEventData data)
    118.     {
    119.         PointerEventData pData = (PointerEventData) data;
    120.         NavMeshHit hit;
    121.         if (NavMesh.SamplePosition(pData.pointerCurrentRaycast.worldPosition, out hit, navMeshSampleDistance, NavMesh.AllAreas))
    122.         {
    123.             destinationPosition = hit.position;
    124.         }
    125.  
    126.         else
    127.         {
    128.             destinationPosition = pData.pointerCurrentRaycast.worldPosition;
    129.         }
    130.  
    131.         agent.SetDestination (destinationPosition);
    132.         agent.isStopped = false; // replaces agent.Resume();
    133.     }
    134.  
    135.     public void OnInteractableClick (Interactable interactable)
    136.     {
    137.         if(!handleInput)
    138.         {
    139.             return;
    140.         }
    141.  
    142.         currentInteractable = interactable;
    143.         destinationPosition = currentInteractable.interactionLocation.position;
    144.  
    145.         agent.SetDestination(destinationPosition);
    146.         agent.isStopped = true;
    147.     }
    148.  
    149.     private IEnumerator WaitForInteraction ()
    150.     {
    151.         handleInput = false;
    152.  
    153.         yield return inputHoldWait;
    154.  
    155.         while(animator.GetCurrentAnimatorStateInfo(0).tagHash != hashLocomotionTag)
    156.         {
    157.             yield return null;
    158.         }
    159.  
    160.         handleInput = true;
    161.     }
    162.  
    163. }
    164.  
    Camera -
    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3.  
    4. public class CameraControl : MonoBehaviour
    5. {  
    6.     public Camera myCamera;
    7.     public GameObject ObjectToFollow;
    8.  
    9.     private Vector3 CameraPos;
    10.        
    11.  
    12.     private void Start()
    13.     {
    14.         CameraPos = myCamera.transform.position;
    15.     }
    16.  
    17.     private void Update()
    18.     {
    19.  
    20.         CameraPos.x = ObjectToFollow.transform.position.x;
    21.         myCamera.transform.position = CameraPos;
    22.  
    23.  
    24.        
    25.     }
    26.  
    27. }
    28.  
    Box -
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class Interactable : MonoBehaviour
    4. {
    5.     public Transform interactionLocation;
    6.     public ConditionCollection[] conditionCollections  = new ConditionCollection[0];
    7.     public ReactionCollection defaultReactionCollection;
    8.  
    9.     public void Interact()
    10.     {
    11.         for (int i = 0; i < conditionCollections.Length; i++)
    12.         {
    13.             if (conditionCollections[i].CheckAndReact())
    14.                 return;
    15.         }
    16.  
    17.         defaultReactionCollection.React();
    18.     }
    19.  
    20. }
    21.  
    Reaction script
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class ReactionCollection : MonoBehaviour
    4. {
    5.     public Reaction[] reactions = new Reaction[0];
    6.  
    7.     private void Start()
    8.     {
    9.         for (int i = 0; i < reactions.Length; i++)
    10.         {
    11.             DelayedReaction delayedReaction = reactions[i] as DelayedReaction;
    12.  
    13.             if (delayedReaction)
    14.                 delayedReaction.Init();
    15.             else
    16.                 reactions[i].Init();
    17.         }
    18.     }
    19.  
    20.     public void React()
    21.     {
    22.         for (int i = 0; i < reactions.Length; i++)
    23.         {
    24.             DelayedReaction delayedReaction = reactions[i] as DelayedReaction;
    25.  
    26.             if (delayedReaction)
    27.                 delayedReaction.React(this);
    28.             else
    29.                 reactions[i].React(this);
    30.         }
    31.     }
    32.        
    33.  
    34.  
    35. }
    36.  
    "What is the root position of the objects that get clicked on?"
    The position of the box at the moment (I have been moving it to test) 0.76, 0.149, 0.03. The InteractionLocation is parented to the Box and it is 0,0,0