As we have said before, some of the main features of unreal 4 are put together by uobject needles. To make it more interesting, uobject will face and avoid problems sooner or later, therefore, you should make sure that uobject is ready for other topics. What does uobject do? PRIVATE:
?
Reflection system
?
The uobject system builds the core of the entire unreal reflection system. Each uobject comes from a uclass. This class can be generated by the unreal header tool (which follows the official website name: UHT in the future, it can also be generated by Blueprint (ublueprintgeneratedclass ). Reflection can be said to be the basis for building mainstream engines. For most people in China, it may be more familiar with the reflection built by unity through mono. Its importance is self-evident.
There is a huge amount of reflection, so I will not mention it. Its biggest function is to dynamically generate code at runtime, which can save a lot of coding workload. Otherwise, for a complex interface like ue, it is absolutely not enough for all hardcode and 100 people, and the time required for the change is unacceptable. With reflection, much of the rest is a well-understood path: attribute Editor Automatic Generation, automatic message packet sending and receiving, automatic serialization, automatic generation of BP nodes, automatic interface interaction between BP and C ++, automatic shallow copy and deep copy, and even according to the set rules copy ...... Not listed.
The commonality is the same: Get class, get property, or get function, analyze the properties of property and function, and then set value, get value, invoke function ......
?
Garbage collection and lifecycle management
?
Uobject builds an illusory garbage collection (GC) system. GC has different opinions, but the bloggers are optimistic. Recently, the company encountered such a problem: the script needs to issue a dynamic package, so it needs to manually generate a dynamic package in the script and link it to the package. To achieve this goal, I have to create a node in the script to generate a dynamic package. Then the problem arises. We have to have a node to recycle dynamic packages, otherwise, the dynamic package cannot be recycled ...... So I finally gave up and went back to the old road of adding various reserved in the package ...... With GC, you don't need to worry about this in most cases ...... You need a plan to understand and recycle such things, that is, to bother them. It is not the scope of their business.
The existence value of GC is not to make things simple and simple. In more cases, it can save you a lot of programming effort and focus on the real focus. The cost of checking errors when a GC error occurs may not be greater than the cost of forgetting to write a delete statement, but may be smaller.
The illusory garbage collection system basically starts from the root and keeps traversing all the properties and marking them as in use. Finally, traverse it again to confirm which objects are not marked for use and delete them. Basically, you don't need to worry about this process. Because of the reflection function, the related information is automatically processed by UE. There are several notes:
"Singleton", always exist, directly addtoroot.
Class F does not take garbage collection, but Class F contains Class U. In this case, you need to pay attention to addreferencedobjects. Add the U class in Class F to the GC tree.
In classes, the uobject attribute marked as uproperty will be automatically added to the GC list of the current class, but it doesn't mean whether or not it is not specific. It's just a habit to write it by hand.
The uobject in tarray and TMAP will be automatically added to the GC list, but it should not be written if it is STD: vector and STD: map, add addreferencedobjects manually.
?
Resource management
?
The last role of uobject is to build an illusory resource management system. Including resource search and resource reference management.
First, let's talk about the name of an illusory object. Because all resources are uobjects, the name is the same as that of uobject. As required, it is the [class name'] path name/asset name. [Package path.] object Name: [attribute name] ['] (generally the Class Name of the Object + a numeric suffix ). For example:
Brush '/script/engine. Default _ brush'
Billboardcomponent '/script/engine. Default _ textrenderactor: SPRITE'
/Engine/templateresources/mi_template_basegray_03_metal.mi_template_basegray_03_metal
This name resolution is slightly different from that of ue3 and udk. ue3 manages packages based on upk, and restricts that the upk package under the content folder cannot be renamed, so the preceding path name is not required. Ue4 is based on asset. Different sub-directories of content can have uasset with the same name. Therefore, path names are indispensable. In addition, the asset and upk are not much different. We will talk about the package later, which also refers to the uasset, although it does not look like a package.
Theoretically, all uobjects can be loaded by staticloadobject (in fact, this is true), but many classes have special implementations based on loadobject, such as uclass (blueprint class ), staticloadclass is required, while loadmap and levelstreaming are required for a map. The main difference between these variants is that some special processing and operations will be performed for the corresponding situations. However, the core cannot bypass staticloadobject. Therefore, to understand this staticloadobject, we actually understand the main resource organizational structure of the illusion.
The main process is as follows:
Parse the path and find the corresponding package (uasset or upk). If not, load the package.
Checks whether the object has been loaded. If the object has been loaded, it is returned directly.
Loading resource packages,All objects in the resource package are pre-loaded (preload is created and called, and postload is called for resources that require postload ). At the same time, ulinkerload is created when a package is loaded. This linkerload automatically analyzes the association between each package and other packages and records the reference of this package to other packages through imports, use exports to record objects in this package.
After loading, check whether the target object is a redirector. If it is a redirector object, it indicates that "there was a package here, but it was moved to a new place", and it will be relocated to the necessary place.
After talking about this, you actually understand the principle of Simplicity: all objects in the illusion are named by a unique name that contains the path, path in the package, and object class name. All the illusory packages will record references to other packages.
Therefore, once the path of a package, the path of the object in the package, and the object class name change, the old resources may be lost and redirected.
Of course, there are also some mechanisms to help you correct the problem (for example, redirector ctor, redireconfig in engine. INI). However, it is a remedy and cannot be guaranteed by 100%. If yes, you can solve the problem by locating the resource reference. However, in the worst case, data may be lost (the most common cause is that the BP class name is modified, as a result, the Child BP class cannot find the parent BP class, and the Child class cannot be used normally. The Child class can only be deleted and reused ......)
Therefore, before transferring the ue4 package path and modifying the resource name, you must back up the package. It is best to perform similar operations in a unified manner after all the prototype iterations are completed, and archive or issue SVN and git frequently.
?
Precautions:
?
Redirector needs to remind you that the resource file must be moved from one folder to another in the unreal, and must be moved in the editor. This is because the reference relationships between unreal resources are guaranteed by the object name mentioned above, while the path name is part of the object. If the name is incorrect, it is very prone to problems. After the editor moves the resource, sometimes it will find that there is a small tail of about 1 kb in the path where it is located before the move. This small tail is redirector. Also, do not manually delete it, but in the resource viewer, delete the redirector by running the fix up command of redirector (filter enabled.
Open redirector first
Then fixup, or
Right-click the folder and fix up redirectors in folder.
?
Because the package is "link load", the reference will be analyzed during the loading process, so if the package is broken, the speed will be slowed down due to more file access. If a single package contains a large amount of data, the loading speed of a single package may also slow down. In the final analysis, it is a trade-off. (Generally, 10 1 k> 1 10 K)
?
The transient object is not stored on the disk. The transient package (gettransientpackage) is a special package. All temporary objects should be created in this package.
?
Asynchronous is not actually asynchronous. Loadobject is loaded with a series of global variables, and these global variables are not locked during maintenance, so they cannot be asynchronously loaded. So although you can see loadpackageasync on the interface, the implementation is implemented by distinguishing time slices from each frame in the main thread. But is it really necessary to read a multi-threaded package? The access speed of a mechanical hard disk is itself the biggest limiting factor. The multi-thread reading process does not actually help the CPU.
?
For more information about asynchronous loading of a large amount of disk or network data, see texture streaming (Why does texture do streaming only? This is because it is the most resource-consuming thing in the game, the resources of the ten models are not necessarily comparable to the previous one). First, the object and a small amount of basic information are loaded as placeholders, and the actual data of the object is loaded slowly in other threads. If you have similar requirements, consider this solution. However, it seems unnecessary. For example, it is enough to take the main thread time slice for asynchronous loading of common roles in our games.
?
The resources in the editor will be marked as standalone, which still exists when there is no reference, and there are other cases that will not be GC. Please note that.
Unreal 4 random 6 object and serialization