so im trying to make a inventory that was made with blueprint and move it to c++ but the problem is, is that i dont know how to move it, and for exmaple now i’m thinking of just moving a UI variable to a c++ class (inventoryComponent) but i dont know how. im really new to this so bare with me if i dont understand
Well, if it’s a widget component (Text, CanvasPanel or similar, even other UserWidget), you can create in C++ a variable with same type and name, just need to make it BindWidget. For example, if you have a Text widget component with name “TextName” in you widget and you want to move this variable to C++ class, you’ll need to create in C++:
UPROPERTY(<your extra specifiers like BlueprintReadWrite>, meta=(BindWidget))
UTextBlock* TextName;
If it’s an ordinary blueprint type (int, string, Actor reference…), just create UPROPERTY field in C++ and replace blueprint variable with your C++ class field.
well i was thinking of taking a whole UI setup (inventory Ui ) to be a variable in c++ so i can access it, or basically im trying to move a variable i have in blueprint to c++. something like this
If I’m inderstanding you correctly, you want to access your 3 variables (button, grid and custom widget) in C++. That’s what BindWidget is for: in C++ you creates a UPROPERTY with BindWidget meta specifier (just creat a field, don’t init them) and after that creates in BP your widget component in design page (or just create in C++ fields, in your case).
It’s OK with button and grid element, but you can’t do it easily with Parent variable, because you can’t use blueprint as C++ type - you need to create a field of parent type of that variable (if UI_W widget inherits from UUserWidget, you can use only UUserWidget as a type of this variable in C++, but if it inherits from a custom widget class inherited from UUserWidget, you can use a custom class).
Sorry for answering late
ok so if i understand correctly about making a variable of UI, should i write something of
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UUserWidget UI_W;
Yes, except one thing: you need to make a pointer:
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UUserWidget* UI_W; // you need to make a pointer, not an ordinary variable
aha ok, and it doesnt show in the blueprint variable section when typing this but instead i have to find it or search for it in the blueprint search bar, right?
also another thing im little confused about is, its about the inventoryComponent class, so if i want to have my inventoryComponenet class to be connected with either my charcter or an object/actor, like how its done with blueprint. you open up your characters blueprint, and in component you add the component you have made, and its connected.
so is including the cpp class enough for it to be connected or do i also need to call functions from the inventoryComponent class?
sorry if its sounds confusing
Yes, inherited fields don’t shows in variable sections, but they’re still accessible via blueprint search bar (if any of BlueprintReadWrite or BlueprintReadOnly modifiers used).
Such component is a UActorComponent child, you need to init it like other actor components (Static/SkeletalMeshComponents, for example): make a UPROPERTY field and init default components in constructor.
oh i see now, that cleared alot of things for me now, i think thats all for the questions that i have, thank you for your time