Blueprint Library - GetScrollOffset Issue.

[FIXED] See posts below

Hi, I have a problem trying to make a blueprint function library.

My case is the following. I created a scroll box using UMG in the editor and I trying to use the GamePad. this is the set up:

&stc=1

All seems fine but I not see any “Get” related with the position of the scroll. I see a node that go to the end of the scroll so I suppose the engine have some way for calculate the last scroll position. If I can’t know this position/offset when I scroll down my variable “scroll offset” can go to infinite… and so when I try to scroll up , the scroll bar not move until the scroll value is = to the end of the scroll value.

So I try to made a blueprint function library to have some “Get’s” that I miss available on blueprints.

I must say , I have some programing background , Python , javascript , php but 0 Experience in c++

I Start watching c++ tutorials, reading the Rama tutorials about the blueprint Functions Libraries etc… and well now I’m more familiar with the language I know about the :: for indicate the function is inside a calss, some about pointers ( not to match clear to me for now), what is .h and .cpp etc…

I so after that I try create my 1 blueprint function library and this is what I have

.h


// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "Kismet/BlueprintFunctionLibrary.h"
#include "MyBP_Functions_library.generated.h"

/**
 * 
 */
UCLASS()
class MYFUNCTIONSLIBRARY_API UMyBP_Functions_library : public UBlueprintFunctionLibrary
{
    GENERATED_BODY()

public:
        UFUNCTION(BlueprintCallable, Category = "MyBPLibrary")
            static FString GetHappyMessage();

        UFUNCTION(BlueprintCallable, Category = "MyBPLibrary")
            static float GetMyFloat();

};

.cpp



// Fill out your copyright notice in the Description page of Project Settings.

#include "MyFunctionsLibrary.h"
#include "MyBP_Functions_library.h"


//Happy Message
FString UMyBP_Functions_library::GetHappyMessage()
{
    return FString("Victory! Victory BP Library Works!");
}


float UMyBP_Functions_library::GetMyFloat()
{

    float MyFloat;
    //float MyFloat = 0.5;

    //this->GetScrollOffset()
    //MyFloat = SScrollBox::GetScrollOffset();
    //MyFloat -> SScrollBox::GetScrollOffset();

    return MyFloat;
}

As you can see , returning a float and a string is fine , but I have no idea how get the value of the scroll or for the max scroll…

I find this on the wiki:

https://docs.unrealengine.com/latest/INT/API/Runtime/Slate/Widgets/Layout/SScrollBox/GetScrollOffset/index.html

Can someone point me to what I need to learn to get this value from other class in other function, or some example to see? or say me what I’m doing wrong and the correct way to do it ? , I’m getting crazy …
(I try to understand some stuff on victory plugin from Rama but no luck, any specific part to see on this plugin?)

Thanks in advance

Greetings!

For any one of us to help you more, we need more info about what exactly your goal is

Can you explain the entirety of what you want your BP node to do?

I know a scrollbar is involved, but where is it coming from exactly?

Are you getting the scroll position from a UserWidget / ScrollBox widget?

Rama

Hi Rama , thanks for you response.

Sure I will try, Well I have a scrollbox for show the scores when the game ends and I want to use the gamepad to scroll up and down to see the scores.

&stc=1

The ScrollBox is editable so I can access on graph editor

On this scrollbox I put 1 children for each score (the children is a horizontal box in another widget)
on construct I load some values form a saved file and I pass the values to the children and add the children to the ScrollBox

&stc=1

Graph.PNG&stc=1

The node setup on the image , is the is the Graph for the widget where I put my Scrollbox (In UMG).
I comment a little more the image, basically I grab the value for the movement of the stick on the gamepad, I create a variable on the editor for count the scroll offset. Start at 0 , if the stick move down (-y) add 5 if move up (+Y) subtract 5 each tick and then I use this variable for set the scroll offset on the scrollBox.

The problem is , I must set up a max Scroll manually because not have any node that tell me the max scroll , or the end Scroll offset etc… only a node for go to the end , or to the start and the node you see on the image for set the scroll offset. If I not Set the Max Offset manually then I move the stick down , my variable scrolloffset can go to the infinite , and then when I want scroll up again , the scroll bar not start moving until my variable is equal to the value for the end of the scroll. But set up manually is a problem because I don’t know how many scores I can have, If I need display more child’s I need increase this number.

I try to calculate the scroll getting how many children’s I have on the scroll box and multiply the value for the Y size of every children ( the font size) but give me some value that not match

BTW, Any idea of how is calculated the Max offset or how say in the node, the end?

&stc=1

Mm I think I find something… what I use is a UScrollBox right?

So I thinck I can’t use the SScrollBox::GetScrollOffset() if I want create a blueprint function library for have a node returning this value. BTW the protect is made in blueprint, no code just for the blueprint library using the add code to project on the editor.

I thought I could see in the code how the end of the scroll is calculated in “ScrollToEnd” function but , I not fully understand the code

ScrollBox.h


/**
     * Updates the scroll offset of the scrollbox.
     * @param NewScrollOffset is in Slate Units.
     */
    
    /** Scrolls the ScrollBox to the bottom instantly during the next layout pass. */
    UFUNCTION(BlueprintCallable, Category="Widget")
    void ScrollToEnd();

ScrollBox.cpp


void UScrollBox::ScrollToEnd()
{
    if ( MyScrollBox.IsValid() )
    {
        MyScrollBox->ScrollToEnd();
    }
}

So what I understand here is , when I call the ScrollToEnd() if MyScrollBox (the “scorespanel” in my graph") is valid , (exist?) then, MyScrollBox point to ScrollToEnd() ?

And the function is void , so not return value right?

A little bit confused now…

Finally! It was easier than I thought, and at the end I have not had to use c ++, It can be done in blueprints.

I’ve been a little digging in the code and I discover that I had in my hands a great node for use. “Get Desired Size” this node give me the size that would have the ScrollBox once all the children are placed in it. So subtracting the Y Size of my ScrollBox to that value (the desired size) , I can get the total scroll value or in other words the Max Scroll Offset , the end of the scroll etc…

Also I discover that is easy get the desired size for the children’s so with some math is possible scroll where a specific children is placed.

I post an image of my node set up, maybe help to someone.

&stc=1

Greetings!

Yay! And Thanks!

Wohoo! Glad you figured it out!

And very nice of you to share your research with everyone!

Thanks Lui!

Rama

1 Like

Thanks Rama, all your tutorials and your questions have helped me a lot

At least now I know a little of c++ and how the API work

When I finish this protect I will try to learn more C++ I’ve noticed that know c++ is like have the power! so I need learn more.

Greetings!

Hee hee! Yes UE4 C++ is so powerful!

All you really need to do is check your pointers and then the whole power of UE4 C++ is available to you and you can do anything you want!

My entry level guide to UE4 C++ goes over pointers, the only complicated part of C++ when it comes to using the UE4 Runtime API

Entry Level Guide to UE4 C++
https://wiki.unrealengine.com/Entry_Level_Guide_to_UE4_C%2B%2B

:slight_smile:

Rama

Yea , I studied your page on the wiki :wink: , and some videos about pointers… what I have clear is , pointers point to a specific place in the memory ( so don’t need copy all data every time you want do something, get or set). I need learn how to use * and & and how to use & when you don’t know if the var have the *. Uops, yea now I understand better what you mean by “check you pointers”. hehe I will try some things later , thanks Rama !

Here a solution if your scroll box is not in a canvas pannel. Overlay Stats being the upper hierarchy of my scrollbox