Assign imported texture2D at run time, to Actor Picture

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Alexhapki
Posts: 3
Joined: Mon Mar 11, 2019 9:55 pm

Assign imported texture2D at run time, to Actor Picture

Post by Alexhapki »

Hi Tony,
Sorry for bothering you again.
I wrote a script to read customs portraits Textures2D from player´s harddisk. I can import them to a C# variable, e.g.

Texture2D playerPortrait

But how I can assign that playerPortrait texture to Actor ["Player"], so I can switch to texture imported from hardisk?

Ps. Videogame in beta version in Steam now! Would you mind if i added your logo and Dialogue System to my website to let know people it was made with Unity and Dialogue Manager as the core? The Essence Reaper Ritual.
https://steamcommunity.com/app/674840

Thanks for everything
Alex.
User avatar
Tony Li
Posts: 21061
Joined: Thu Jul 18, 2013 1:27 pm

Re: Assign imported texture2D at run time, to Actor Picture

Post by Tony Li »

Hi,

Congratulations on your beta release! I'll PM you a logo image if you'd like to use it.

To assign a portrait image at runtime, add a script with an OnConversationStart method to the Dialogue Manager. The OnConversationStart method might look something like this:

Code: Select all

void OnConversationStart(Transform actor)
{
    DialogueManager.conversationModel.actorInfo.portrait = // (sprite for conversation actor)
    DialogueManager.conversationModel.conversantInfo.portrait = // (sprite for conversation conversant)
}
Alexhapki
Posts: 3
Joined: Mon Mar 11, 2019 9:55 pm

Re: Assign imported texture2D at run time, to Actor Picture

Post by Alexhapki »

Hi Tony,

Thanks for the quick reply.
I am getting an error though;
NullReferenceException: Object reference not set to an instance of an object

1) I have assigned the Actor transform on the conversation trigger on Awake.
2) Texture2D is assigned (I tested it being used on a GUI element).
3) I import my custom Texture2D as follows;
www = new WWW(mySaveDirectory); //mySaveDirectory is path to folder and file / texture name on harddisk.
Texture2D img1 = www.texture;

public void OnConversationStart ()// (Transform actor)
{

DialogueManager.ConversationModel.ActorInfo.portrait = img1;

}

Would you know what may be wrong?


Thanks!
Alex.
User avatar
Tony Li
Posts: 21061
Joined: Thu Jul 18, 2013 1:27 pm

Re: Assign imported texture2D at run time, to Actor Picture

Post by Tony Li »

Hi,

What version of the Dialogue System are you using?

What part is causing the null reference exception?
Post Reply