I'm trying to make a switch on a wall that changes visually (to a different sprite) as the player interacts with it.
I can't find a way in the ActionList Editor to switch which sprite an Object or Hotspot is using, but perhaps I'm not looking in the right place?
I've seen posts mention using an animation for something similar, but this object (and many others) literally only has the 'on' and 'off' sprite, so creating the whole animation workflow every time an object changes seems a bit overkill?
Or am I missing a much simpler process for this?
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
Welcome to the community, @Refrigerator747.
Using the Object: Animate Action is the recommended way of altering which sprite a single Sprite Renderer uses. Though appreciably creating an Animator, and then Off/On animations may feel like overkill (though similar lightswitches can recycle these), this workflow does allow such changes to be recorded by the save system via the Remember Animator component.
It is technically possible to have a custom Action that replaces which sprite a Sprite Renderer displays - and I can assist with this if you'd like - but if it's not driven by animation then leaving and re-entering the scene would cause it to revert to its original sprite.
The other approach, which doesn't involve creating additional assets, is to place both state sprites in the scene as separate GameObjects, and then - using a pair of Object: Visibility Actions - control which one is shown. This change too can be recorded by the save system, va the Remember Visibility component.
Thanks!
-And thanks for answering so quickly. I appreciate that.
My plan was to also store the state of the switch in a global variable, as it needs to affect the lighting in other rooms/scenes. Does that have an impact on what the best approach would be?
And would you suggest to control that light setting using the 'Scene Manager' (cutscenes) or 'Actionlist Starter'?
Not so far as switch's visuals go, no. If you need to rely on many such variables, however, be aware that you can use the "/" character in variable names to organise them into sub-categories, e.g. "Lights/Kitchen".
Both will work just fine, but I'd recommend the use of ActionList Starter as it keeps logic compartmentalised.