Why are some of my animations not working in a Viewport (WorldModel)

I am trying to play animations inside a ViewportFrame, using WorldModel, however half of them don’t play.

First case, the Open animation never plays, even tho I set it up just like the Shake animation.

Secondly, the Idle animation of the dog never plays either. I am unsure if this is due to same reason the Open animation not playing, or possibly due to it being a skinned mesh? (Idk, maybe skinned meshes don’t work in viewports?)
ezgif.com-gif-maker (70)

-- Load animations
local Shake = NewCrate.AnimationController.Animator:LoadAnimation(NewCrate.Shake)
local Open = NewCrate.AnimationController.Animator:LoadAnimation(NewCrate.Open)
	
-- Shake animation
for i = 1, 3 do
	Shake:Play()
	
	wait(1.25)
end
	
Open:Play()

I can’t see any reason why the open animation would not play? It has a higher priority than the Shake animation, so it’s not being overwritten. Can see the exact Open animation below in the animation editor.

Code for the dog model. Once again, this Idle animation 100% works in the world, but doesn’t play when in the viewport

local WorldModel = Instance.new("WorldModel")
		
-- Copy over the pets contents
for _, v in pairs(PetModel:GetChildren()) do
	local New = v:Clone()
	New.Parent = WorldModel
end

-- Set postion
WorldModel.PrimaryPart = WorldModel.HumanoidRootPart
WorldModel:SetPrimaryPartCFrame(
	CFrame.new(0, 0, 0) + Vector3.new(0, 1.25, 0)
)

WorldModel.Parent = Viewport

-- Load pet animations
local Idle = WorldModel.Humanoid.Animator:LoadAnimation(WorldModel.Idle)
Idle:Play()
2 Likes

Skinned mesh animations do play in ViewportFrames, however, they do not cause the ViewportFrame to update. To see the animation update each frame, you need to trigger a ViewportFrame update each frame. This can be done by changing a property of the mesh on .Heartbeat (toggling .Anchored on/off each frame works, for example)
I noted this here & talked to Roblox staff about it in DMs but it’s still an issue.

2 Likes

How could I update the viewport frame then? Or would just changing the property cause it to animate?

1 Like
local viewportModel -- your skinned mesh model

local onOff = true
game:GetService("RunService").Heartbeat:Connect(function()
    onOff = not onOff
    viewportModel.PrimaryPart.Anchored = onOff
end)

This will result in the ViewportFrame updating every frame and therefore you’ll be able to see your animation playing. It’s a workaround and quite annoying, this definitely needs a better solution.

2 Likes

Hi @Fm_Trick, just letting you know we’ve made a fix for this bug. Let me know if you’re still having trouble with it, thanks for reporting!

3 Likes

Was it ever pushed?
I’m still having issues with this

It may be a new issue, can send us repro instructions?

It’s basically the same thing , I’m trying to play an animation on a model that’s wrapped by a “WorldModel” , within a viewportframe , and the model is a skinned mesh , it only updates when I update properties of the model itself.

I will message you privately for help reproducing this.

1 Like

I’m also experiencing the same issue. I can send a repro if needed.

1 Like

I will message you for the repro. Do you have Beta Features → Cage Mesh Deformer turned on? If so, can you try with it off?

2 Likes

I’m having the same issue as this. The skinned mesh animation works in the WorldModel in Studio only, but when I turned off the Cage Mesh Deformer Beta it stopped working in studio as well. Turned it back on but it still will not work in the live game.

So the beta seems to fix it for me at least…Just can’t use it

Has anyone gotten this to work?

I think animations are broken in WorldModels. I’m not using any Beta features. Let me know if a repro is helpful.

If animations do work on character models in a VPF, I’d like to understand if there is anything special that needs to be done. Is there a demo of it? I imagine it’s a very common use case for building shops/avatar editors.

1 Like

I have managed to do characters (with animations) in a viewport, by simply having a dummy rig stored in RepStorage, and cloning it into the Viewport.WorldModel and then using HumanoidDescription to get it to match my character. No beta features turned on either

--// Setup the character model for the viewport
local function SetupCharacter()	
	if Player.UserId <= 0 then return end
	
	-- Create camera
	local ViewportCamera = Instance.new("Camera")
	ViewportCamera.FieldOfView = 50
	ViewportCamera.CFrame = CFrame.new(-0.25, 1.5, 5)
	ViewportCamera.Parent = PlayerViewport
	
	local DummyClone = Dummy:Clone()
	DummyClone:SetPrimaryPartCFrame(CFrame.new(0, 0, 0) * CFrame.Angles(0, math.rad(200), 0))
	DummyClone.Parent = PlayerViewport.WorldModel
	
	local HumanoidDescription
	
	local Success, Error = pcall(function()
		HumanoidDescription = Players:GetHumanoidDescriptionFromUserId(Player.UserId)
	end)
	
	if Success then -- Set dummy
		DummyClone.Humanoid:ApplyDescription(HumanoidDescription)
	else
		warn(Error)
	end
	
	-- Get objects and parent to WorldModel
	for _, v in pairs(DummyClone:GetChildren()) do
		v.Parent = PlayerViewport.WorldModel
	end
	
	DummyClone:Destroy()
	
	PlayerViewport.CurrentCamera = ViewportCamera
	
	-- Do idle animation
	local Idle = PlayerViewport.WorldModel.Humanoid.Animator:LoadAnimation(PlayerViewport.WorldModel.Idle)
	Idle:Play()
end
1 Like

Hello! Were you able to get the dog pet in the original post to animate? I’m running into the same exact problem where its shows up in the ViewportFrame but just won’t show any animation. I’m also using similar code to you.

local object = script.Parent.Muck

local camera = Instance.new("Camera")

camera.CFrame = CFrame.new(object.RootPart.Position + (object.RootPart.CFrame.lookVector*4),object.RootPart.Position)

camera.Parent = script.Parent

script.Parent.Parent.CurrentCamera = camera

local animation = Instance.new("Animation")

animation.AnimationId = "https://www.roblox.com/asset/?id=7913452598"

local AnimationController = object.AnimationController

local animationTrack = AnimationController:LoadAnimation(animation)

animationTrack.Looped = true

animationTrack:Play()

Thank you!

1 Like