NPC Clothing/Styles

Im trying to make this type of thing in my game where when NPCs spawn, they are spawned with different clothing styles like a Green Shirt or a Red Shirt and its not a set style its the same NPC Model but with different sprites everytime it is generated

How would I achieve this?

You add a new object, say for Shirt, with different animations or different frames, whichever way you want to go about it, then you make the different shirts inside that object.

Then if you would like to make it randomized you would pick from a number like 1 to 3 for example. 1 is green, 2 is red, and 3 is yellow. You can make a variable and just use the RandomInRange(1,3) to determine which one it is, then do this process for the pants, shoes, hair, or whatever you want!

And to attach the object to the player you could just put an event with no condition and have it go to a point on the player.

Would it be a global or object variable?

Actually you don’t need a separate variable, you can directly set the animation by number:

change the number of the animation of Shirt = RandomInRange(1,3)

You can access the animation number that is currently displayed with Shirt.Animation::Index

Also, instead of using events, I would give the Sticker behavior to the clothing items and then Stick them to the player when created. This will move the item around with the player, and you can also use “is stuck to an object” conditions to pick the clothing objects later.

so the sticker doesn’t attach to the player and doesn’t follow them either

Did you position the object first? Sticking doesn’t change the position, you have to first line up the objects and then stick.

Sticking doesn’t work at all and the object is just being dragged and is following that player

Don’t you want it to follow the player? Maybe if you show us some screenshots of your events and the result then we can see what the problem is

I do but its like dragging and not on top of the player
Screenshot 2025-05-01 10.25.21 AM
This is the event used

https://game-previews.gdevelop.io/1746109574030-840179/index.html
This is the thing so you can see what is happening

I see, you only need to stick it once. If you want to use collision to put on the clothing, you will need another condition to prevent this from triggering constantly. You’ll also need to position the clothing as I mentioned… when you Stick an object, the object follows from wherever you Stuck it, which in this case is whatever position you collided with the object.

CAT is in collision with Clothing    |  Stick Clothing to CAT
Clothing is not stuck to CAT         |  Position of Clothing = Cat.X(), Cat.Y()

If the clothing sprite is not the same size as the cat sprite, you might need offsets to get it to line up right (i.e. Cat.X() + 1, Cat.Y() - 6)

By the way, to have a “not stuck” condition, look for the “Is stuck to an object” condition and then invert it

okay so it works now, Thank you

1 Like

so turns out when I had done the shirt randomizations it didn’t quite work right
Screenshot 2025-05-05 12.49.14 AM
Because when the player has interacted with the Sprite then it will scroll through different styles instead of staying at the randomly chosen style

Is there a way to fix this?

An advanced way to do this is with the new custom objects you can create two objects short and body. Use the pre-scene events to set positions (might lag if there are many ais). You can further use on creation to change the clothing animation and make a more editable system.

I don’t see any benefit to this and it doesn’t answer the specific questions being asked.

That’s because you did not add the condition to stop the event from triggering again.

Each event is processed once every game tic. If your game is running at 60fps, that means your events happen 60 times per second. So you have this event where the only condition is “player is in collision with clothing”. So if the player is in collision with the clothing for 1 second, then this event will happen 60 times.

There needs to be another condition that will prevent this from firing off constantly. “Trigger once” is one possible way, but I try to avoid using that since I feel it is better to have direct control over the event. That’s why I suggested adding this condition:

(inverted) Clothing is stuck to Player

With that condition, when you collide with the object it will only go on to do the actions if the clothing is not already stuck to the player. (sticking the object does not prevent collisions)

So I tried both ways and they didn’t work at all
“Trigger Once” doesn’t do anything and the condition you suggested doesn’t work at all

Can I see how you did it? For “not stuck” you need to invert the condition, either by clicking on the invert condition toggle in the large condition editor dialogue, or by selecting in in the events sheet and pressing J


Here’s how I did it

Ok, the condition is fine, problem is that those are separate events. Drag the “clothing is stuck” condition up to the above event, below the collision part. And drag the “change number of animation” up as well (order doesn’t really matter for that one)

Okay so I did it and now the Clothing isn’t sticking to the Player when interacting with it
Screenshot 2025-05-05 2.32.57 PM
Here is what everything looks like

Nevermind!!

I figured out a way to fix it but I also realized that I can turn it into like a mystery box mechanic as seen in the Mario Kart Games except with clothing!!!

1 Like