Apparel not ticking when worn

Started by Distman, July 30, 2017, 08:13:10 PM

Previous topic - Next topic

Distman

So, another ticking problem...

I have a piece of apparel with a custom comp. Ticking fine when it lays on the ground but stops when equipped. I guess the apparel thing is actually despawned when worn, therefor the ticker stops?

Any ideas how i can get the comp to keep ticking when worn? Also, as far as i see there's no way to add a comp to, for instance a pawn, on the fly (add same comp to pawn when worn, remove comp when apparel is de-equipped)?

Thanks for any input.
/Distman

Distman

Well, yeah Pawn_ApparelTracker DeSpawns the apparel when it's worn. No wonder the ticking stops.
There is a PostDeSpawn method on apparel, but it's hard to find any decent use in this case.
I can't get any variable that reference if it's despawned because it's worn, who wears it and i can't add comps to a pawn on the fly.

I guess i can spawn a ghost/invisible object with said comp following the pawn around, but i would rather solve it in a less crude way.

To explain a bit more what i'm after:
I have a ThingComp that adds/adjust severity of a hediff on pawns when in sight and range. I want to be able to apply this to apparel and weapons, affecting pawns in proximity.
Think of it like a magic armor/weapon that instills fear in your enemies when worn...  ::)

Any ideas?
/Distman

jamaicancastle

You could try making it a stat. So every pawn has a native "scariness" stat that starts at 0, or even at some value for certain pawns (bears are scary, right?) and the proximity effect is part of the pawn code that goes off if they have a non-zero scariness. Then all the apparel actually has to do is increase the stat.

Distman

Yeah, i guess i could do something like that.
Sigh... It was just so beautiful having a comp i could slap on different stuff for effect.

skullywag

Depending on what you want to do apparel can have some extras thrown on it, for example:

https://github.com/Skullywag/MedievalShields/blob/master/Source/MedievalShields/Apparel_Shield.cs

this however does obv require c# knowledge.
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?

Distman

Thanks for the link!

Hmmm... I'm confused. This code suggests that the apparel is actually not despawned when worn. Otherwise non of these methods would be invoked when the pawn is damaged.

I did a test class decendant from Apparel, with just a Tick function with a message. Works fine when apparel is on the ground but as soon as you wear it the Tick stops. Pawn_ApparelTracker confirms that any apparal worn will be despawned.

How in the name of Scully Wag did you go around this?

skullywag

The apparels Drawwornextras is called from tick elsewhere in render. So you can basically fake stuff per tick in there. Dont use the tick method.
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?

Distman

You sir are an angel!
:-*

Works like a charm.

/Distman

Quote from: skullywag on August 02, 2017, 03:05:58 AM
The apparels Drawwornextras is called from tick elsewhere in render. So you can basically fake stuff per tick in there. Dont use the tick method.

skullywag

Glad I could help. When your done with your mod and have it out in the wild dont forget to PM me for access to the modders discord, if you want to chat modding of course.
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?