Some common functions of UE Actor

        Because I usually use blueprints to write project functions, so what is mentioned here is the implementation method in the blueprint.

Get the blueprint class itself: self

Get the object where the blueprint is located:

Destroy objects: equivalent to Destroy(Acor1) in unity

Delayed destruction of objects: two methods, equivalent to Destroy(Acor1,1f) in unity

 

 Access Actors through components:

Access components through Actor:

Obtain a reference to an object in the level blueprint : first select the object TestCube1 in the level, and then do the following in the level blueprint

Find objects:

 

 Add tags to Actor: Determine whether an Actor contains tags:

 Show and hide Actors:

        SetVisibility needs to pass in a Boolean parameter to control showing or hiding. ToggleVisibility is a switch function, constantly calling will make the object constantly switch between showing and hiding. The control ability of the function with Hidden is stronger than that of the function with Visibility. Control the two separate variables under the Rendering component:

 

 

 


2022.11.15 added

Get Actor position, angle, scale:

Instantiate Actor: Similar to Instantiate(prefab) in unity, use Spawn Actor From Class


 

 

2022.11.14 added

If you add a blueprint script component to an object, then you cannot use methods such as GetActorOfClass in this blueprint, but use the GetComponentOfClass method. For example, I added the MyPlayer blueprint script component to the third-person character ThirdPersonCharecter in the demo project, and obtained the corresponding blueprint variables through the following method.

Play audio: play audio on the left and the whole scene can be heard, and play audio at a certain position on the right

 Play video: There are two types: playing video in the scene and playing video on the UI.

Play video in scene

1. Create a new folder named Movies in the project folder Content , drag the video into this directory, a File Media Source file will be generated, double-click to view the properties, the path has been set. The name must be Movies, so that the packaging can be successful.

 2. Create a Media Player, check the pop-up box, a Media Texture will be automatically generated, and then put a Plane in the scene to play the video, and adjust the size and angle slightly.

 

There are three options to pay attention to when you click on this Media Player, they are Play on Open (automatic playback), Shuffle (random playback), and Loop (loop playback). Here we will use the default.

Then right-click the MediaTexture to create a material. When opening this material, pay attention to the MaterialDomain option. If it is used in a 3D scene, use the default Surface. If it is used in the UI, select the last UserInterface.

 Then drag the created material to the plane where the video is played

 3. Add a blueprint script to Plane to control the playback of the video. The name is up to you, and the default name is used here.

 4. Add a MediaPlayer type variable, and open the eyes to indicate the public variable. Then compile it, and the name of the Plane that plays the video becomes the same as the name of the blueprint. Here I changed it to Plane_Video for easy understanding and management. At the same time, a variable name MediaPlayer with the same name as defined in the blueprint appears on the property panel of the Plane. Then we Drag the MediaPlayer file you just created

 

 5. Add playback function. Select the Plane_Video object, click Edit Blueprint on the properties panel, and then click the orange button to open the blueprint editor.

Then drag the MediaPlayer variable into the editing area, select Get to get the variable, and then use the following method to play the video.

 The OpenSource resource selects the FileMediaSource file that is automatically generated when we drag in the video, and then calls the Play function. In the same way, Pause and Close represent pause and close respectively. After OpenSource is initialized, Play can be used in other places, not necessarily used together.

        At this time, the video has no sound. Select the blueprint Plane_Blueprint of the plane to play the video, click AddComponent, search for MediaSound, add this component, and then drag the video player named NewMediaPlayer into the MediaSound MediaPlayer variable. At this time, there will be sound when playing the video . And we can also directly drag MediaSound into the scene to get the component object, and then call SetVolumeMultiplier to set the volume.

 If it is playing online video, just call the OpenUrl function, and fill in the address of the online video as the url parameter.

 Play video on UI

 1. We drag an Image on a UI blueprint control UI1 to play the video. Then select the previous MediaTexture and right-click to create the material, and select UserInterface for the MaterialDomain type. At this time, the material looks like a black icon.

 2. Select the Image to play the video, find the Image of Brush, click the drop-down arrow at 1 to select the video UI material we just created, or click the magnifying glass icon, then switch to the main interface and click the corresponding video UI material with the left mouse button , and then switch back and click the left arrow button at 3, so that we can also select the video UI material we need.

Among them, there are two buttons in the upper right corner of the UI blueprint, which are used to design UI and write logic respectively. If you can’t see the red default event node in the logic writing interface, remember to click the EventGraph button to enter the logic code editing area.

 3. Define a MediaPlayer type variable in UI1 of the UI blueprint control, and the default value selects the MediaPlayer object we defined. Then refer to the previous method to play. If there is no sound, just hang a MediaSound component on an object. When the video is paused or closed, MediaSound should also be paused and closed.

 

At the beginning, the video screen was black, but there was sound, indicating that it was played, but the picture could not be seen. Then I suspected that it was a material problem. I opened the material and looked at it. The picture on the left was moving, but there was no line connecting the lines on the right. So I connected the lines and saw the picture in the scene. The reason is that when creating a material, the default is Surface type, and then when changing the material type to UserInterface for playing video, I found that the connection was disconnected, and the system cheated me.

 Finally, the video was played, which was the picture of someone playing the piano.

Guess you like

Origin blog.csdn.net/qq_34256136/article/details/127807290