Announcement

Collapse
No announcement yet.

Access persistent/current level script from another blueprint

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

    Access persistent/current level script from another blueprint

    I've seen variations of this thread around, but haven't come across the following case:

    I'd like to execute a custom event in my level blueprint script from my game blueprint. I've had no issue implementing interfaces where the two can communicate, however when i create a variable to hold the reference to the level script, (which would allow me to access the desired custom event), i can't save the script because of an external reference.

    to achieve this with an interface, the only way i can think of is to create a listener in the tick function of the level script that will switch based on whatever game blueprint condition it is listening for, however this seems inefficient.

    what would be the proper way of achieving this result?
    Earthborn Interactive | Flutter Bombs | MageWorks

    #2
    You can make a actor variable(with ActorClassName_C as type for custom blueprint) and use construction script to set it.
    You can't use event graph for persistent instance because it could be deleted or it's subcomponent changed and so on and you would have to recompile your script again.
    Also with this you still need to check if the actor you get has the interface implemented, and then call the function you want.

    But if you want to access level script itself and do things with it, say inside a Pawn, I think that's kinda in the scope of not recommended.
    Because you can always have a event trigger do the job for you, which sends event to your desire actor.
    Or you can refer to Blueprint_HUD example that shows you how to pass a persistent level object reference into your player controller, which you can then access its info, and call its functions if they valid.
    Unreal Engine 4 Game Framework diagram for relation of all major base object types
    Unreal Engine 4 Input Event diagram, scroll down to section Input Processing Procedural
    Resident Evil Classic Camera
    RPCs official document, Must Read
    Everything you should know about replication

    Comment


      #3
      You are not allows to directly reference the Level Blueprint from inside a Class Blueprint. This would prevent you from using it in different maps. Instead I think you want to use an Event Dispatcher. Hopefully this tutorial video I made will help: http://youtu.be/s5pIrpI7py8?t=1m55s
      Lead Programmer - UE4 Animation/Physics/Audio Team - Epic Games
      Twitter: @EpicJamesG

      Comment


        #4
        yep, event dispatcher solves the issue, thanks!
        Earthborn Interactive | Flutter Bombs | MageWorks

        Comment


          #5
          Hey James

          just came across this because I'm trying to communicate with the level blueprint, from a button clicked function in a widget blueprint. I followed your tutorial but the event dispatcher isn't showing in the level. Would it not work from a widget blueprint?

          Comment


            #6
            I believe it will not, because the level needs to contain the actor with the dispatcher in order for the events to show up. I'm trying to solve the same problem right now, without much luck.
            The Flame in the Flood - travel the river, evade predators, fight the elements.

            Comment


              #7
              Originally posted by Stuckbug View Post
              I believe it will not, because the level needs to contain the actor with the dispatcher in order for the events to show up. I'm trying to solve the same problem right now, without much luck.
              SilentX sent me a jpeg of how he thinks it would work over DM, but the link is broken. I think i'm going to do it in C++/Slate. I realize if I do it that way its more demanding but I can get it hooked up to levelscriptactor and the save game class in a much more robust way. Once I've done it, it will make aspects the game build alot easier I think...

              Comment

              Working...
              X