Announcement

Collapse
No announcement yet.

Set/Get variable

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

    Set/Get variable

    Hi,

    I have setup a menu system before the game loads my main level in which you can choose a difficulty by pressing a widget button.
    In my character bp I have a float for the difficulty which will contain 1-3, I'm trying to set the variable on click, which should be pretty simple, then when my level loads read this variable but I'm having trouble with this. It seems I can read it, but can't set it. Any help?

    Thanks


    This is in my widget blueprint where I wanted it to set the variable
    Click image for larger version

Name:	set.png
Views:	1
Size:	39.3 KB
ID:	1208303

    This is in my level blueprint, I want to get this variable as the level begins but it just seems to return the default value as if it was never set
    Click image for larger version

Name:	get.png
Views:	1
Size:	24.0 KB
ID:	1208304

    #2
    First of all, you're trying to get the player pawn in the main menu, is it really spawned there? Check if the cast fails.

    Secondly, are you saving and loading? When you switch levels, every actor in the previous level is destroyed and then the new level loads with whatever you put in it. Your character does not inherently remember anything from previous levels, so you need to implement saving and loading, or using the .. game state? which persists between levels.

    Comment


      #3
      Hi, SilverfireInt.
      You must make you logic correct - variable difficulty can set in game instance for example.

      Comment


        #4
        All classes are recreated when a level is opened. This means you cannot store any information over different levels. The only class that isn't recreated is the GameInstance. You need to store such information in that class. Alternatively you could use a SaveGame object but the GameInstance is most likely what you should use here.
        Twitter | Multiplayer TopDown Survival Kit | Fog of War | Game Stats Kit

        Comment


          #5
          Thanks for the fast replies.

          I found this youtube tutorial which explains if anyone else is having a similar issue.
          https://www.youtube.com/watch?v=K_4CWDxwufg

          All sorted thanks again!
          Last edited by SilverfireInt; 01-26-2017, 08:52 AM.

          Comment

          Working...
          X