Skip to content
This repository has been archived by the owner on Mar 19, 2019. It is now read-only.

Commit

Permalink
Dynamic material instance reset fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ufna committed Jul 8, 2014
1 parent 44b20cd commit dbb1772
Showing 1 changed file with 38 additions and 22 deletions.
60 changes: 38 additions & 22 deletions Source/VaQuoleUIPlugin/Private/VaQuoleUIComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,26 @@ void UVaQuoleUIComponent::InitializeComponent()
{
Super::InitializeComponent();

// Create web view
if (!WebUI)
// Update enabled state
SetEnabled(bEnabled);

// Force materials initialization
if (!bEnabled)
{
WebUI = VaQuole::ConstructNewUI();
ResetUITexture();
}
}

// Init WebUI for the first time
ResetWebUI();
void UVaQuoleUIComponent::ResetWebUI()
{
// Update transparency state
SetTransparent(bTransparent);

// Resize texture to correspond desired size
Resize(Width, Height);

// Open default URL
OpenURL(DefaultURL);
}

void UVaQuoleUIComponent::BeginDestroy()
Expand Down Expand Up @@ -91,10 +103,20 @@ void UVaQuoleUIComponent::ResetMaterialInstance()
}

// Create material instance
MaterialInstance = UMaterialInstanceDynamic::Create(BaseMaterial, NULL);
if (!MaterialInstance)
{
UE_LOG(LogVaQuole, Warning, TEXT("UI Material instance can't be created"));
MaterialInstance = UMaterialInstanceDynamic::Create(BaseMaterial, NULL);
if (!MaterialInstance)
{
UE_LOG(LogVaQuole, Warning, TEXT("UI Material instance can't be created"));
return;
}
}

// Check again, we must have material instance
if (!MaterialInstance)
{
UE_LOG(LogVaQuole, Error, TEXT("UI Material instance wasn't created"));
return;
}

Expand Down Expand Up @@ -259,21 +281,6 @@ void UVaQuoleUIComponent::UpdateLoadingState()
}
}

void UVaQuoleUIComponent::ResetWebUI()
{
// Update enabled state
SetEnabled(bEnabled);

// Update transparency state
SetTransparent(bTransparent);

// Resize texture to correspond desired size
Resize(Width, Height);

// Open default URL
OpenURL(DefaultURL);
}


//////////////////////////////////////////////////////////////////////////
// View control
Expand All @@ -282,6 +289,15 @@ void UVaQuoleUIComponent::SetEnabled(bool Enabled)
{
bEnabled = Enabled;

// Create web view if we haven't one
if (bEnabled && WebUI == nullptr)
{
WebUI = VaQuole::ConstructNewUI();

// Init web UI for the first time
ResetWebUI();
}

if (WebUI)
{
WebUI->SetEnabled(bEnabled);
Expand Down

0 comments on commit dbb1772

Please sign in to comment.