Hello,
I had a question while making a simple game with Unreal.
I did a lot of searching, but couldn’t find a clear answer, so I uploaded it myself.
In Unity, in order to access a child’s component, you can register a variable with getchild() or public and then drag and drop it to access it at any time.
But, Unreal can only be used if the child component is registered with get all actors of class, get factor of class, cast, etc., and even if the variable is registered with public, it cannot be registered.
In Unreal, you must always use get actor or cast when accessing a child object or an object within the level.
I even need to cast the component access of the actor I dragged in from the level blueprint.
The question here is, can cast be considered similar to Unity’s getchild() and getcomponent()?
Why can’t Unreal register a mouse drag in a public variable?
→ Although Unity is invisible to the eye, it would be even more interesting if the engine itself was performing the casting. let me know.
Personally, I don’t really use the get argument. Instead, I usually use cast, and I also try to register this only once at start.
Frequently used components are often cast in beginplay, and cast when used if cast briefly in the middle.
What I’m curious about here is how I work. In Unreal, the only access methods for components such as actors, game managers, instances, etc. are cast, get actor, etc.?
It’s okay to swear if it helps. I believe that you can only grow if you have feedback.
For your variable LoadingBP of type WIP Loading which i guess is a widget class. Represent a reference of a created instance of WIP Loading.
So for example you do Create Widget (WIP Loading) it will create a ref: WIP_Loading_0, you do this again, it will become WIP_Loading_1.
These instances are created ingame, that why you can’t select them from your default value. To access them, you need to set the variable when you create/spawn your bp class.
Thank you very much for your reply. I am impressed by your answer.
Thank you for showing me how to register loadingBP’s public variable!
I have additional questions.
I used to work as a Unity designer! So I’m sorry for constantly comparing it to Unity.
When creating objects in Unity, I tend to be quite careful in terms of performance.
So I want to know. Is it cost-effective to create an instance of a widget instead of casting it and referencing it?
generally speaking you want to use interfaces anywhere you might need to cast, there is also getcomponentbyclass() to get childcomponents but i still just use an interface for that
Yes it not recommended to use Casting, you will need to use Interface to exchange variable/events between bp classes so that you only take what is needed and not the whole class.
Also note that whenever you do casting/reference another bp class/spawn or create another bp class, these are loaded into the memory as well even if you are not directly using them or connected them.
A bp class is loaded into the memory when it is spawned/placed on the level map(including what ref bp class it has). You can use Reference Viewer to see that (right click on your bp class in the content browser)
So 3 solution:
Interface
Level Streaming
Soft Reference
if you really want performance.
Last thing, bp is not slow, it actually the white line between 2 node which is slow compared to a cpp, otherwise a Node itself is as fast as a cpp.
For example if you loop a string to get a character, it better to use inbuilt function such as Split / SubString instead of doing a manual ForEachLoop.
You are mixing two terms
You cannot cast if you do not have the object instantiated
You don’t need cast if you already have the reference
You only need the cast when you work with inheritance
Casting is faster than interfaces
Don’t go crazy with soft reference until it’s not a problem, switching from one mode to another is not difficult if you need it.
Check this: