Hi all,
I’m making a 2d top down game with shadows on many objects that are created at runtime by a script that makes a new game object as a child, copies the sprite of an object that wants a shadow, changes the colour and alpha so that it looks like a shadow, and rotates it onto the floor. This is then also rotated as the game plays as a big part of the game is the time of the day so the shadow moves around the character as if it was moving with the sun.
Imgur: The magic of the Internet - a picture in case that’s hard to visualise.
Anyway, when animating the player character I am stumped as to how I’m supposed to get the shadow to animate when the player character animates.
I’ve tried:
-adding an animator and setting the animator controller of the shadow to the animator controller of the player using runtimeAnimatorController
-when I change the player’s animation in script using .Play, do the same for the child (by finding the child and getting a reference to it’s animator component).
This however does nothing on the shadow whilst animating the player fine.
I then tried making an animator override controller and setting the controller of the shadow’s animator to be that instead, but still nothing on the shadow.
Is it possible to do what I’m trying to do? I really hope so ._. Googling has lead me nowhere so I’m at a loss right now.
Many thanks in advance for any help you can give - apologies if I’m missing something really simple!
Bump - no one knows anything about this?
I’ve tried many many things to test this and what I find bizarre is that if I make a GO with just the sprite and animator controller on it (essentially what the shadow is) before I run the game and make that the child of the player character, that animates exactly as I want it to. I then thought the rotation might be an issue, but stopping that from happening doesn’t change anything either. It doesn’t animate.
If I watch the animator controller of the generated shadow object, it runs through the animation exactly as it should, just the GO isn’t being animated.
This leads me to believe the problem is something to do with the object being created at runtime.
Here are the two objects, one created at runtime and one created beforehand. They look pretty identical to me.
The only difference is the scale and rotation and as I’ve said turning those off doesn’t change the problem. PlayerCharacterSh animates and PlayerCharacterTODShadow doesn’t.
Anyone? I really need this to work for my game to function as I’d like and being as I can recreate the behaviour on other objects not created at runtime I’m totally stumped as it seems like it SHOULD work fine.
Thanks to much to anyone who can help!
Seems like this should work.
So - your setup is
master - charcter controller
child of master - character sprite
child of master - character shadow
?
Are you saying - you can get the functionality you desire - when the shadow GO is not instantiated at runtime?
setup is:
master GO: sprite with animator and scripts attached
child of master: shadow sprite
I eventually gave up trying to instantiate the shadow GOs at runtime and simply manually make the child GOs, then reference them as public variables. It now animates exactly as it should. Never understood why it didn’t work as it seemed like it should have with instantiated GOs, but I have a working solution even if it’s slightly different to what I initially intended, so I’m okay. Thanks for the reply though 
1 Like