Ads keep us online. Without them, we wouldn't exist. We don't have paywalls or sell mods - we never will. But every month we have large bills and running ads is our only way to cover them. Please consider unblocking us. Thank you from GameBanana <3

How to Properly Move Hud Elements in Base Game - A Tutorial for Baldi's Basics.

Don't like having something like the stamina bar be in the top middle and you want it to be on the bottom left corner? Fear not! Because this tutorial will show you how to move Hud Elements PROPERLY!

WHAT YOU WILL NEED:


Let's get started.

STEP 1: Setting Up

Open Up dnSpy and open up your Assembly-CSharp.dll. (It should be in the Managed Folder in "BALDI_Data")

Go to "-" and look for "GameControllerScript"

Once you find it open it.

STEP 2: Basics

Right click on anything and click "Edit Class", Make a void. Here's a template for you to save time.
public void SetHud()
    {
        
    

Now we are going to make a local RectTransform variable in the SetHud void for our Hud Element RectTransform. I am going to use the stamina bar as an example. Put THIS in the void.

RectTransform staminaTransform = this.player.staminaBar.gameObject.GetComponent<RectTransform>();

This will connect the Stamina Transform variable to the Stamina Bar GameObject by Getting it's RectTransform component, meaning we can start moving it around now.

STEP 3: Moving and Anchoring It

Now it's time for the fun part, Actually moving it! So let's start off by Changing it's anchored position. Should be simple enough.

Start by typing in your RectTransform variable. We're going to change it's anchored position so type in anchoredPosition and then add " = new Vector2(0f, 0f);"

If you've done it correctly, it should look like this:
staminaTransform.anchoredPosition = new Vector2(0f, 0f);

Now we are going to place it on the bottom left corner. Let's change our Vector2 values.

The value to your left is your X position, whilst the value to your right is the Y position. So let's change our values to be -235 for the X position and -340 for the Y position.

If you've done it correctly, again it should be like this:
staminaTransform.anchoredPosition = new Vector2(-235f, -340f);

Make sure to trigger the SetHud void in the start method and there you go, you've successfully moved the Stamina Bar! but wait.. If you play it in a different resolution (like 640x480) It's in a weird spot, That's not where we want it. The reason why it's like that is because it's incorrectly anchored. We want to change the said anchor to be on the bottom left corner so it stays there in every resolution. So let's get to anchoring. It's actually fairly simple.

Let's start by Changing the Vector2 values of the anchoredPosition again.

So instead of (-235f -340f) it will be (85f, 10f), Now we will start anchoring.

Type in these:
staminaTransform.anchorMin = new Vector2(0f, 0f);
        staminaTransform.anchorMax = new Vector2(0f, 0f);
        staminaTransform.pivot = new Vector2(0.5f, 0.5f);

If you've done it all correctly your SetHud void should look like this:
public void SetHud()
    {
        RectTransform staminaTransform = this.player.staminaBar.gameObject.GetComponent<RectTransform>();
        staminaTransform.anchorMin = new Vector2(0f, 0f);
        staminaTransform.anchorMax = new Vector2(0f, 0f);
        staminaTransform.pivot = new Vector2(0.5f, 0.5f);
        staminaTransform.anchoredPosition = new Vector2(85f, 10f);
    }

And then you should be done! Your stamina bar should be on the bottom left corner, and it's even anchored so it works on different resolutions! Enjoy!
  • NotFurnace avatar
    NotFurnace username pic Joined 2y ago
    Bye!
    DooD Flag Affiliation: DooD
    652 points Ranked 52,554th
    18 medals 2 rare
    • Returned 1000 times Medal icon
    • 10 submissions featured Medal icon
    • One month a member Medal icon
    • 6 months a member Medal icon
    • 1 year a member Medal icon
    • Returned 100 times Medal icon
    NotFurnace avatar
    NotFurnace
    DooD Flag
    Affiliation
    DooD
    26d
    anyway to move the "you need rest" text? i tried anything but it did not work
    Polish modder i guess
    URL to post:
  • ChineseScout avatar
    ChineseScout Joined 3y ago
    This is offline
    332 points Ranked 67,193rd
    1y
    Okay how do I make my RectTransform variable?
    ???????? avatar
    Mantra
    ????????
    URL to post:
  • Kracc avatar
    Kracc username pic Joined 4y ago
    Offline
    2,910 points Ranked 21,525th
    16 medals 1 legendary 2 rare
    • 2019 Top Contributor Medal icon
    • 10 submissions featured Medal icon
    • Submitted 20 Gamefiles Medal icon
    • One month a member Medal icon
    • Submitted 5 Gamefiles Medal icon
    • Returned 100 times Medal icon
    2y 2y
    i had a problem.. it became a "component." on the left RectTransform instead of "staminaTransform." or i messed up something?
    A.K.A KrazzersKits!
    URL to post:
  • saintza4 avatar
    saintza4 Joined 4y ago
    Baldi Manager
    Generation Done
    8,227 points Ranked 1,198th
    25 medals 2 legendary 3 rare
    • Returned 5000 times Medal icon
    • Became a Ripe Supporter Medal icon
    • Returned 1000 times Medal icon
    • Reached 50 subscribers Medal icon
    • Achieved Game Manager clearance Medal icon
    • Returned 100 times Medal icon
    2y
    You do not need the token things in the script, those are made when the compiler compiles the script, so you don't need to put it there anyway.
    Great Coder, Texturer, Modder avatar
    Mantra
    Great Coder, Texturer, Modder
    URL to post:
  • SirOofy90 avatar
    SirOofy90 username pic Joined 3y ago
    i am not online
    5,097 points Ranked 2,176th
    19 medals 2 legendary 2 rare
    • Became a Ripe Supporter Medal icon
    • Returned 5000 times Medal icon
    • Returned 1000 times Medal icon
    • Thanked 50 submitters Medal icon
    • One month a member Medal icon
    • Returned 100 times Medal icon
    2y
    With the example you did with the stamina bar the 'YOU NEED REST!' text didn't come with the stamina bar itself, so I just made it that the 'YOU NEED REST!' text doesn't appear when you run out of stamina.
    baldi basic gaming avatar
    Mantra
    baldi basic gaming
    URL to post: