Forum rules - please read before posting.

Switching Expression Portraits

Hi,

So my player has a number of skins, for which I call a trigger to switch ion On Start depending on the scene. I am using Lipsync Portraits with expressions, but is there a way to change the expressions image with a script?

«1

Comments

  • Yes - expressions can be modified by accessing the Char script's expressions List:

    public AC.Char myCharacter;
    public Texture2D newTexture;
    
    public void UpdateExpressionTexture (int index)
    {
        myCharacter.expressions[index].portraitIcon.ReplaceTexture (newTexture);
    }
    
  • Great! Thanks!

  • Is there a way to switch a cursor set too?

  • In what context?

  • I have a set of animated cursors for certain scenes (real world) and a set of cursors for cartoon world, abs wish to swap them depending on scene
  • You can call the CursorIcon class's ReplaceTexture function to replace its texture, e.g:

    AC.KickStarter.cursorManager.pointerIcon.ReplaceTexture (newTexture);
    

    To get an API reference to access each of your cursors, right-click each cursor's texture field in the Cursor Manager.

  • Awesome thanks!!
  • Being a bit of a noob, what would wrap this code in the script? Really appreciate your help (specifically for ReplaceTexture

  • Just place it in a parameterless public function, i.e.:

    public Texture2D newTexture;
    
    public void ChangeCursor ()
    {
        AC.KickStarter.cursorManager.pointerIcon.ReplaceTexture (newTexture);
    }
    

    Then add it to a new GameObject, make it a prefab, remove from the scene, and use the Object: Call event Action to trigger the prefab's ChangeCursor function when you wish to change the cursor's texture.

  • so i get this error

    Assets/Sleepytime Village/Scripts/ChangeCursor.cs(9,13): error CS0116: A namespace cannot directly contain members such as fields or methods

    using

    using System.Collections;
    using UnityEngine.UI;
    using UnityEngine;
    using UnityEngine.SceneManagement;

    public Texture2D newTexture;

    public void ChangeCursor ()
    {
    AC.KickStarter.cursorManager.pointerIcon.ReplaceTexture (newTexture);
    }

  • i think it might be easier to replace entire cursor manager on scene start - so i could have two cursor managers and choose which one on start of scene, is that possible?

  • otherwise i was trying to write this, but had errors;

    Assets/Sleepytime Village/Scripts/CursorUtils.cs(18,70): error CS1061: 'Texture' does not contain a definition for 'ReplaceTexture' and no accessible extension method 'ReplaceTexture' accepting a first argument of type 'Texture' could be found (are you missing a using directive or an assembly reference?)

    using System.Collections;
    using UnityEngine.UI;
    using UnityEngine;
    using UnityEngine.SceneManagement;

    public class CursorUtils : MonoBehaviour
    {
    public Texture2D newTexture;
    public int textureIndex;

    public void SetMainCursor( Texture2D texture )
    {
        AC.KickStarter.cursorManager.pointerIcon.ReplaceTexture (newTexture);
    }
    
    public void SetTalkCursor( Texture2D texture )
    {
        AC.KickStarter.cursorManager.GetCursorIconFromID (0).texture.ReplaceTexture (newTexture);
    }
    
    public void SetUseCursor( Texture2D texture )
    {
        AC.KickStarter.cursorManager.GetCursorIconFromID (1).texture.ReplaceTexture (newTexture);
    }
    

    }

  • using UnityEngine;
    
    public class CursorUtils : MonoBehaviour
    {
        public Texture2D newTexture;
        public int textureIndex;
    
        public void SetMainCursor( Texture2D texture )
        {
            AC.KickStarter.cursorManager.pointerIcon.ReplaceTexture (newTexture);
        }
    
        public void SetTalkCursor( Texture2D texture )
        {
            AC.KickStarter.cursorManager.GetCursorIconFromID (0).ReplaceTexture (newTexture);
        }
    
        public void SetUseCursor( Texture2D texture )
        {
            AC.KickStarter.cursorManager.GetCursorIconFromID (1).ReplaceTexture (newTexture);
        }
    
    }
    
  • Hi, so I have tried this and it just seems to remove and not replace the cursor (i am using animated cursors (spritesheets)

  • using UnityEngine;

    public class CursorUtils : MonoBehaviour
    {
    public Texture2D newTexture;
    public int textureIndex;

    public void SetMainCursor( Texture2D texture )
    {
        AC.KickStarter.cursorManager.pointerIcon.ReplaceTexture (newTexture);
    }
    
    public void SetTalkCursor( Texture2D texture )
    {
        AC.KickStarter.cursorManager.GetCursorIconFromID (0).ReplaceTexture (newTexture);
    }
    
    public void SetUseCursor( Texture2D texture )
    {
        AC.KickStarter.cursorManager.GetCursorIconFromID (1).ReplaceTexture (newTexture);
    }
    
    public void SetExamineCursor( Texture2D texture )
    {
        AC.KickStarter.cursorManager.GetCursorIconFromID (2).ReplaceTexture (newTexture);
    }
    
    public void SetPickUpCursor( Texture2D texture )
    {
        AC.KickStarter.cursorManager.GetCursorIconFromID (3).ReplaceTexture (newTexture);
    }
    
    public void SetExitCursor( Texture2D texture )
    {
        AC.KickStarter.cursorManager.GetCursorIconFromID (4).ReplaceTexture (newTexture);
    }
    
    public void SetExitUpCursor( Texture2D texture )
    {
        AC.KickStarter.cursorManager.GetCursorIconFromID (5).ReplaceTexture (newTexture);
    }
    

    }

  • Have you assigned the texture in the "New Texture" Inspector field, and does it match the number of animations as your default texture?

  • edited September 2021

    Yes they are identical in size and frames

    https://www.dropbox.com/sh/vwcll1sczn8x0ep/AAAFHdXntqVhRUIwf5qMvaXBa?dl=0

    I am calling the texture from my project and not scene

  • Your screenshot of your Object: Call event Action crops out an important message box: event parameters cannot be set in the Action.

    You must amend your script to store the texture within it's Inspector, so that the function you call needs no parameter. See my example from earlier:

    public Texture2D newTexture;
    public void ChangeCursor ()
    {
        AC.KickStarter.cursorManager.pointerIcon.ReplaceTexture (newTexture);
    }
    
  • Sorry, so I would put in 'Pointer' (name of .png cursor in project) for example where (newTexture) is in the script? Even though it is dropped in to call event here?

    https://www.dropbox.com/sh/vwcll1sczn8x0ep/AAAFHdXntqVhRUIwf5qMvaXBa?dl=0

  • Yes: again, parameters assigned in the call event Action are ignored.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.