Animated Mesh duration/replay it

Discussions about Coding and Scripting
Post Reply
User avatar
Barbie
Godlike
Posts: 2806
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Animated Mesh duration/replay it

Post by Barbie »

On reworking the health items in MonsterHunt I run into problems with the NaliFruit which uses the animated 'UnrealShare.NaliFruitMesh' - unfortunately I don't know details about Meshes.

1) When an animation is over (=it has reached its end frame), how can I restart that animation from start frame?
Background: Before a NaliFruit is picked up, it runs through the animations "root", "grow" until "Waver" - so far so good. But if it is picked up, all next respawned NaliFruits don't run any animation, they are fully grown at the moment of spawn. If I don't load MonsterHunt, it works as expected: a new spawned NaliFruit runs through all animations.

2) How can I determinate the "normal" time between the start and end frame of an animated Mesh?
Background: It would be a nice feature to change the grow rate depending on environment. For example it could grow faster in water and slower in lava. For this feature to implement I have to know the time between start and end frame. But this point is really optional. 8)

For your convenience some lines of the stock NaliFruit.uc code:
Spoiler

Code: Select all

class NaliFruit extends Health;
...
#exec  MESH SEQUENCE MESH=NaliFruitMesh SEQ=Root	STARTFRAME=1	NUMFRAMES=1
#exec  MESH SEQUENCE MESH=NaliFruitMesh SEQ=Grow	STARTFRAME=1	NUMFRAMES=26
#exec  MESH SEQUENCE MESH=NaliFruitMesh SEQ=Waver	STARTFRAME=27	NUMFRAMES=2
...
auto state Pickup {
	function Timer() {
		HealingAmount += 1;
		SetTimer(0.5,True);
	}
...
Begin:
	PlayAnim('Root');
	FinishAnim();
	HealingAmount = 0;
	Sleep(FRand()*3);
	SetTimer(8.5,False);
	PlayAnim('Grow',0.036);
	FinishAnim();
	SetTimer(0.0,False);
	LoopAnim('Waver',0.1);
}
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Animated Mesh duration/replay it

Post by JackGriffin »

Some quick answers...
1) This is because the fruit enters into pickup state the first time. It runs the animations, finishes, then waits. When a player "picks it up" it does like all pickups in UT, it spawns a copy onto the player while the "real" one goes to sleep and becomes hidden. When the fruit comes back it is already in state pickup so it doesn't run the anims again. This is just an oversight and could actually be easily fixed via code.

2) There's no real absolute on animations. It all depends on how it is imported and how detailed the animations were created to be. Take this line for example (it's in the Dragon code I'm working on and just happened to be open):

Code: Select all

#EXEC MESH SEQUENCE MESH=GravRotParticlesFX02 SEQ=RotLoop 	STARTFRAME=0 NUMFRAMES=39 RATE=38.0
Because the rate is set to 38 then it will render at 38 FPS. When you research PlayAnim and LoopAnim you'll see how that factors into the playback. You can speed up or slow down the playback via code but if you leave it alone then the playback will be at 38FPS. This can be different for every animation, it all depends on how it was imported.

Iniquitous has a huge section on all this here:
http://unreal.shaungoeppinger.com/tutorials-ut2004/
It's for UT2004 but the directives almost all also apply in UT. Shaun did exhaustive background work learning all this and his pages detail it the best I've seen. I still go there to research some things.
So long, and thanks for all the fish
User avatar
Barbie
Godlike
Posts: 2806
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Animated Mesh duration/replay it

Post by Barbie »

JackGriffin wrote:could actually be easily fixed via code
Finally I found out how to do that... ^^
The trick is to destroy the awakened Inventory and spawn a new copy of it at the same location - then the full animation is played. Now my NaliFruit is growing up after a respawn. :D

Code: Select all

State Sleeping {

	function EndState() {
	local NaliFruitSB NewNaliFruitSB;

		Super.EndState();
		NewNaliFruitSB = Spawn(Class, none, self.Tag, self.Location ,self.rotation);
		if (NewNaliFruitSB != None)
		{
			NewNaliFruitSB.GotoState('Pickup');
			self.GotoState('','');
			self.Destroy();
		}
		else
			warn("could not create" @ Class @ "at location" @ self.Location);
	}
}
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
User avatar
sektor2111
Godlike
Posts: 6410
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Animated Mesh duration/replay it

Post by sektor2111 »

Aside, I'm not addicted to destroy "MyMarker" "MarkedItem" and the rest of A.I. related things because of an animation which could be done different... btw, I have to fix this too if it's so important.
User avatar
Barbie
Godlike
Posts: 2806
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Animated Mesh duration/replay it

Post by Barbie »

sektor2111 wrote:Aside, I'm not addicted to destroy "MyMarker" "MarkedItem" and the rest of A.I. related things
Yep, I've forgotten that. The following code will do the trick?

Code: Select all

if (NewNaliFruitSB != None)
{
	if (MyMarker != None)
	{
		MyMarker.MarkedItem = NewNaliFruitSB;
		NewNaliFruitSB.MyMarker = MyMarker;
		MyMarker = None;
	}
	NewNaliFruitSB.GotoState('Pickup');
	self.GotoState('','');
	self.Destroy();
}
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
User avatar
sektor2111
Godlike
Posts: 6410
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Animated Mesh duration/replay it

Post by sektor2111 »

Short Recall
Net Code here indeed does need some love. States are changing + display + the rest, and Actor has a poor replication. So I think I must be agree with a NEW actor ... BUT after checking ALL display details. If won't work, in order to do things as should I'm gonna take in account:
- rotation;
- DrawScale;
- event (inventory can trigger something - even a monster... cough);
- tag - tracked by whatever;
- Owner ?
- DM type MH - Bot knows about this stuff only if is linked with InventorySpot - for this chapter I gotta see "editactor class=..." in editor. In ReplaceWith from "Engine.Mutator" there are a couple of hints for dealing with such stuff - I'll use Copy-Paste-Edit :oops: . More simple than rewriting Snow-White story.

Else, this seems a beautiful challenge for doing Net-Code toward animations + respawn which works like a charm OFF-Line and is utterly trash ON-Line.
Edit:
Fixing first untrue speech >
Barbie wrote: If I don't load MonsterHunt, it works as expected: a new spawned NaliFruit runs through all animations.
IT DOESN'T work ON-LINE in any environment - except a FRESH NaliFruit spawned from "Seeds", this is a Net code issue not MonsterHunt issue. I was looking at this stuff in a custom DM with no replacements - has the same problem because bug came from item/actor replication which has nothing to do with MonsterHunt.
For a better image you might do a null DM game-type and then you can see "original" maps what they are, and how they do work Off-Line and On-Line.
Post Reply