- Unreal Engine 4.x Scripting with C++ Cookbook
- John P. Doran William Sherif Stephen Whittle
- 137字
- 2025-02-28 12:28:30
Getting ready
In your UE4 code, you're often going to need to refer to different UCLASS in the project. For example, say you need to know the UCLASS of the player object so that you can use SpawnObject in your code on it. Specifying a UCLASS from C++ code is extremely awkward, because the C++ code is not supposed to know about the concrete instances of the derived UCLASS that were created in the blueprints editor at all. Just as we don't want to bake specific asset names into the C++ code, we don't want to hardcode derived blueprints class names into the C++ code.
So, we use a C++ variable (for example, UClassOfPlayer), and select that from a blueprints dialog in the UE4 editor. You can do so using a TSubclassOf member or an FStringClassReference member.