Ch 5 worry – MessagingManager not firing

Home Forums Books Mastering Unity 2D Game Development Ch 5 worry – MessagingManager not firing

This topic contains 11 replies, has 2 voices, and was last updated by  Simon (darkside) Jackson 3 years, 5 months ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #6278

    Andrew

    Hi All,

    I’ve worked through Ch 5, and I am finding that the MessagingManager class isn’t activating properly.  The wakeup message is never logged to the console, and whenever any of the related events (like a broadcast) try to occur, the Unity message about no valid object reference is logged.

    I tried running the sample scene from the download and that seems fine.  So I guess it might be project settings or something.  I’ve attached the MM script to an empty game object – am I perhaps missing something here?

    Cheers,

    Andrew.

    #6279

    Andrew

    I should mention – I also tried getting the MessagingManager class from the download, placing it into an empty game object in a new, blank project.  It still didn’t wake up.

    #6280

    Hi Andrew.  First off, thanks for being a supporter of my book :D.

    Right, Messaging Manager.

    The first version of the Messaging Manager on page 145, is a simple example which can be attached to any GameObject in a scene to run. In this instance the Awake function will run because it is based on the MonoBehaviour class (which Unity uses for all the management functions, Awake, Start, Update, Draw, etc)

    So there shouldn’t be any reason the Awake call wouldn’t fire when you attach it to any GameObject in a scene.  For example, if you attach the following script to any GameObject in a scene, the awake function will fire and a console message should be logged:

    Now later in Ch 5 we also introduce another pattern using a Singleton Manager in the Conversation Manager

    public class ConversationManager : Singleton<ConversationManager>

    (I also updated the Messaging Manager script in the code in Ch 6 to this method as it means you no longer need to manually add it to the scene)

    In this mode the Script does not Awake until the first time it is called, i.e. when the first event is fired.

    Hope this helps.

    Simon (Darkside) Jackson
    @SimonDarksideJ

    #6282

    Andrew

    Thanks Simon, much appreciated!

    I’m sure I’ve just got a tiny setting somewhere out of whack.  I also noticed that when the receiver and the broadcaster attempt to call on the instance of the MessagingManager I’m getting the NullReferenceException as well, specifically at the call to the instance.  Kind of odd, since there is definitely a game object in there with the manager logic attached.  It’s like the object is invisible and dormant! No awake, not visible to the other classes.

     

    I generally find that going back a chapter or two and retyping it all in tends to solve this sort of thing 🙂

    Cheers,

    Andrew.

    #6284

    No worries, let me know how you get on.

    However that chapter is quite self contained.  If you are getting NullReferenceException’s  then the script for the MessagingManager isn’t active for some reason (which would explain why you aren’t getting the “Awake” console message)

    I just whipped up a quick test using the code from the book and everything seemed to work as expected.  I’ve packages it in to a .UnityPackage for you to try. (start a new project and do Asset | Import Package | Custom Package and select the file, then run)

    You can download it here: https://www.dropbox.com/s/eg44gw9o8tb92mb/MessagingManagerAwakeTest.unitypackage?dl=0

    Simon (Darkside) Jackson
    @SimonDarksideJ

    #6289

    Andrew

    Hi Simon,

    Thanks very much for that! Turns out I had an old fubar – “awake” as opposed to “Awake”!!!  The pitfalls of typing it all in char for char (but I still prefer the learning from doing it). Sorry to have wasted your time so much, I’ll remember to run a diff before bothering you again!

    Cheers,

    Andrew.

    #6294

    Oh it’s not a waste of time if you learned something 😀

    The amount of times I have miss-spelled one of the functions (which if you aren’t using UnityVS isn’t obvious) or used IEnummerable instead of IEnumerator is astounding, followed by a brief face slap.

    It is only through mistakes that we truly learn 😀

    Simon (Darkside) Jackson
    @SimonDarksideJ

    #6313

    Andrew

    Hi Simon,

    I went back to basics and had it all running a treat, then foolishly tweaked something somewhere and now find the MessagingManager class is being destroyed when I navigate from Home to the World.  It’s when I start in the World, then go to Home.  Class is still there.  Then, as soon as I go back to the World – gone!  I’ve put in a stack of Debug.logs and can verify it happens on the World scene load.

    I’ve tried going over all the code, and checked that I haven’t misspelled any reserved functions (like DontDestroyOnLoad).  In spite of that, the singleton just doesn’t make it back to the World scene.  I’ll be darned if I can find out why it’s being killed off.  Just can’t find out why OnDestroy is being activated.

    Hoping to receive any advice, especially if anybody is aware of how the DontDestroy can be overridden. Something is knocking it out somewhere!

    Kind Regards,
    Andrew.

    #6314

    if you look in the sample code you will see I converted the MessagingManager to use the Singleton type manager introduced with the ConversationManager.

    (make sure to clean up / remove the awake methods and so on)

    I’d recommend doing the same since the MessagingManager is a game wide manager (unlike the shop manager which is only used in shops :D)

    Simon (Darkside) Jackson
    @SimonDarksideJ

    #6315

    Andrew

    Hi Simon,

    Brilliant, thanks for that!  I’ll give it a try and see how it goes.

    Cheers,

    Andrew.

    #6339

    Andrew

    Anybody ever get bugs from Unity meta file issues?

    Well it’s all working a treat currently.  After several reboots, and also turning game objects off/on several times for isolation testing, the game project is running nicely.  I’m fairly sure I didn’t change any code, and yet my previous bug is gone.

    So I’m wondering – has anybody experienced bugs that related to meta files, or other Unity system maintained data, that can basically be cleaned up with some housekeeping type functions?  I noticed in Simon’s Singleton class commentary that one can experience ghost gameobjects, so I theorised that maybe such issues could maybe have a longer term effect.  Curious to hear what others have encountered.

    Cheers,

    Andrew.

    #6341

    Hmm, never had any particular issues with .Meta files (provided you have them turned on properly in the Editor preferences).

    They are a must if you use source control.

    Simon (Darkside) Jackson
    @SimonDarksideJ

Viewing 12 posts - 1 through 12 (of 12 total)

The forum ‘Mastering Unity 2D Game Development’ is closed to new topics and replies.