如何从 C++ 调用函数到虚幻引擎中的小部件蓝图 [英] How to call a function from c++ to a widget blueprint in Unreal Engine

查看:31
本文介绍了如何从 C++ 调用函数到虚幻引擎中的小部件蓝图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在蓝图中调用 c++ 变量.我创建了一个小部件蓝图,我必须在该蓝图中的文本块中显示一个变量值.该变量是从 C++ 获得的.是否可以.?请帮助....

How can i call a c++ variable inside a blueprint. I have created a widget blueprint and i have to display a variable value in a text block inside that blueprint. The variable is obtained from c++. Is it possible.? Please help.....

推荐答案

以下是我如何使用 C++ 在 Unreal 中管理小部件的示例

Here is an example of how I manage my Widgets in Unreal Using C++

您想创建一个自定义小部件来作为您的小部件的基础.为此,创建一个继承自 UUserWidget 的 C++ 类:

You want to create a custom widget to base your widgets on. To do this create a C++ class that inherits from UUserWidget:

// Copyright 2014-2016 Blackbriar Softworks, Inc. All Rights Reserved.
#pragma once

#include "Blueprint/UserWidget.h"
#include "XUserWidget.generated.h"

/**
 * 
 */
UCLASS()
class UNSUNGHEROES_API UXUserWidget : public UUserWidget
{
    GENERATED_BODY()


public:

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "XConfiguration")
    FString WidgetName;
};

在编辑器中,您现在想要重新设置您想要访问自定义属性的窗口小部件的父级:

Inside the editor you want to now reparent your widget that you want to have access to custom properties:

Open Widget -> File -> Reparent Widget -> Your C++ Widget Class Name

Open Widget -> File -> Reparent Widget -> Your C++ Widget Class Name

现在您可以访问蓝图小部件内的 WidgetName 或使用数据绑定来显示值./

now you can access the WidgetName inside the blueprint widget or use data binding to display the values./

这是您将属性公开给蓝图的地方:

This is where you expose the property to blueprints:

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "XConfiguration")FString WidgetName;

这篇关于如何从 C++ 调用函数到虚幻引擎中的小部件蓝图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆