I guess i’m doing something stupid but… Right now, I’m trying to get a mp4 video playing when some actions take place, as a cut scene.
Trying to follow some tutorials, I’ve got a objection on my HUD canvas which has the Canvas Renderer component and a Raw Image component which has the Texture being the Video Rended, which is a Render texture. I also have the video MP4 clip and on the canvas, another Object with the Video Player Component which is linked to the Video clip and target texture is the Rendered Texture i said about.
If i tell the video player to play on awake, it’s fine. When I try to play it via script, it brings up:
“NullReferneceException: Object Reference not set to an instance of an object”.
The line it calls a problem:
“MyVideoPlayer.clip = Resources.Load(VidName);”
where MyVideoPlayer is a public static videoPlayer, which is then assigned to the VideoPlayer Component on the canvas (MyVideoPlayer = GetComponent<VideoPlayer)(); at start for the VideoPlayer script). The video itself is stored just in the Resources assets folder and the VidName which is passed as a string is the name of the video with the extension, though i have tried it without the extension…
I’m not quite sure what/if i need to do something to make the videoclip into an instance cause… i didn’t think you bring the video clip itself to the scene… in fact, i did try that and it was kinda not having it… so… would i need to do something to the mp4 to make it an instance? i can’t find an option for it…
Update:
okay… despite a number of guides NOT saying it, i found one that said to add ‘as VideoClip’ to confirm the loaded videoclip as a videoclip… fine… now no error… but no video either…
It is normal. The “as” keyword in C# returns null instead of throwing an exception. NullReferneceException mean you tried to use a null variable. My best bet is MyVideoPlayer = GetComponent is not called, or you destroy it during the game. You can add a Debug.Log(MyVideoPlayer == null) to check if the MyVideoPlayer is null or add a breakpoint.
mm… okay, i did the check with seeing if it’s null and it is…
doing a bit more debuging… it’s clearly the GetComponent line that isn’t working… It’s in the Start function so… I can’t kinda see why… I tried to put it in the LoadVideo function which is where i call the video to play it but it won’t allow it cause that is a public static function…
thanks for your help cause that is really putting me onto the right line, even though i’m still a little confused as to WHY it isn’t running… or how to link it up right… mm… but i’m onto the right track now
so thanks
Update: Yeah, Got it to connect to the Video player… for some reason… the script wasn’t attached. ¬_¬; stupid idiot me…
only problem now is its still not playing the video… need to work on that bit…
But i just noticed two… warnings? not red errors but one yellow and one white…
white: “Unexpected timestamp values detected. This can occur in H.264 videos not encoded with the baseline profile”
yellow: “WindowsVideoMedia error unhandled color standard: 0”.
Checking online… they say ignore the first one as it’s… minor? mm…
second yellow one… seams no help either… odd…
Yeah, the “Unexpected timestamp values detected” warning tells you that we have to offset the video timestamps, and frame accuracy will be impacted negatively because it was not encoded using the baseline profile. For most users, it is not an issue. But if you care, you should encode your file using the baseline profile.
The “WindowsVideoMedia error unhandled color standard: 0” warn that the video file doesn’t specify its color standard and we took a guess and chose BT.709 as it is the most popular. In Unity, we support BT.601, BT.709, and BT.2020. Again for most users, it is not an issue. But if you care or see a color shift because your file is not BT.709, you should specify the color standard while encoding your video files.
I wish this answers your questions!
1 Like
Oh, yep, that helps
the one program i use doesn’t have a way to change the colour profile but that shouldn’t be too much of an issue.
Now i just need to figure out this issue with it playing… i run the play() command after setting the clip… but when i check ‘isPlaying’ it’s false… so… maybe the clip isn’t loading… OR is unable to play because i need it to wait a few ticks first… need to check guides again 
Update:
Ugh… playing around, the video now plays… and everything is fine
thanks again
1 Like