Announcement

Collapse
No announcement yet.

Why can't I cast to level blueprint?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Why can't I cast to level blueprint?

    I need to cast to the level blueprint to get info on what is the current level, so that I would remove the pause option in the menu

    #2
    You can't access the level blueprint from other classes, and you probably don't want to anyway because each one will be different and specific to that level. While you can sort of do this in C++, I really wouldn't recommend it anyway. You can however get the name of the current level, if you need to.

    Level Blueprints are only really designed for map-specific logic (such as a one-off door opening or starting a level sequence etc) - you shouldn't be putting pause menus or general game logic in there (I mean, you can if you really want to - but it's far from the best approach). To be honest, I don't think I've ever actually needed one.

    A good design is to store and reference all of your UI from a HUD class, so that it's managed from one central place that's easily accessible. That way you can tell the pause menu to be removed from anywhere, even the level blueprint.
    Last edited by TheJamsh; 04-01-2018, 07:08 AM.

    Comment


      #3
      Originally posted by TheJamsh View Post
      You can't access the level blueprint from other classes, and you probably don't want to anyway because each one will be different and specific to that level. While you can sort of do this in C++, I really wouldn't recommend it anyway. You can however get the name of the current level, if you need to.

      Level Blueprints are only really designed for map-specific logic (such as a one-off door opening or starting a level sequence etc) - you shouldn't be putting pause menus or general game logic in there (I mean, you can if you really want to - but it's far from the best approach). To be honest, I don't think I've ever actually needed one.

      A good design is to store and reference all of your UI from a HUD class, so that it's managed from one central place that's easily accessible. That way you can tell the pause menu to be removed from anywhere, even the level blueprint.
      Hi man, thanks for your help.
      My pause menu is a separate class, and I discovered that when the player is in the main menu I can call pause menu as well. Thanks for your detailed tutorial, I know understand level blueprins much better and I think I came up with idea how to fix my issue: I ll just make a variable in umg and set it to true when umg is created then I will check if it's not true, then pause menu will appear, thanks a lot
      Last edited by Dudester01; 04-01-2018, 09:41 AM.

      Comment


        #4
        This doesn't quite relate to the original question but for the sake of people who run into this thread some time in the future I'd like to just retort to TheJamsh as there are genuine reasons why one would want to access the current LevelScript actor in code. A project of mine uses it to store all "adjacent" levels to a given streamed level and preload them while unloading the ones adjacent to the room the player came from. The game is structured as a series of rooms, think Metroid Prime style.

        in addition to this every level script actor fetches all objects of type StreamingDoor contained within that level to populate the adjacent levels list so that the process is automated and designers only have to place doors around.

        As a general rule of thumb though, if you have to access the level script actor you'll know it and it is definitely something 99% of people can do without especially when just starting out.

        Comment


          #5
          Hmm I guess that's fair enough - though in my case I would probably write a specific level streaming manager of some kind and access adjacent levels through that, each to their own though. I can only write from personal experience in this case, but I've never really used the Level Blueprint for much.

          Comment


            #6
            Level blueprints can be extremely useful if you have a lot of custom scripted events. Also, quest logic as the level blueprint is the closest thing to custom quest editor Level BP allows using a reference to any object in the level without a hassle.
            But I would never recommend accessing level bp from outside in such case. Event/quest script should be the last thing in the script chain.

            Comment


              #7
              Use an event dispatcher on something persistent like GameMode or PlayerController. Bind an event to the dispatcher in level blueprint BeginPlay. Get a reference to the persistent object in whatever you want to call the dispatcher from, and then call it.
              Last edited by JoSf; 04-02-2018, 06:00 PM. Reason: i should proofread

              Comment

              Working...
              X