Skip to content

Fix for issue with Default material not available when Models are imported at project startup. #345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed Wizard check on default volume profile to also check it is not the default one in package.
- Fix erroneous central depth sampling in TAA.
- Fixed light layers not correctly disabled when the lightlayers is set to Nothing and Lightlayers isn't enabled in HDRP Asset
- Fixed issue with Model Importer materials falling back to the Legacy default material instead of HDRP's default material when import happens at Editor startup.

### Changed
- Improve MIP selection for decals on Transparents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Reflection;
using System.Collections.Generic;
using System.IO;
using UnityEditorInternal;

namespace UnityEditor.Rendering.HighDefinition
{
Expand Down Expand Up @@ -378,9 +379,17 @@ void FixHdrpAssetRuntimeResources(bool fromAsyncUnused)
if (hdrpAsset == null)
return;

hdrpAsset.renderPipelineResources
= AssetDatabase.LoadAssetAtPath<RenderPipelineResources>(HDUtils.GetHDRenderPipelinePath() + "Runtime/RenderPipelineResources/HDRenderPipelineResources.asset");
ResourceReloader.ReloadAllNullIn(HDRenderPipeline.defaultAsset.renderPipelineResources, HDUtils.GetHDRenderPipelinePath());
var editorResourcesPath = HDUtils.GetHDRenderPipelinePath() + "Editor/RenderPipelineResources/HDRenderPipelineEditorResources.asset";
var objs = InternalEditorUtility.LoadSerializedFileAndForget(editorResourcesPath);
hdrpAsset.renderPipelineEditorResources = objs != null && objs.Length > 0 ? objs.First() as HDRenderPipelineEditorResources : null;
if (ResourceReloader.ReloadAllNullIn(HDRenderPipeline.defaultAsset.renderPipelineEditorResources,
HDUtils.GetHDRenderPipelinePath()))
{
InternalEditorUtility.SaveToSerializedFileAndForget(
new UnityEngine.Object[] { HDRenderPipeline.defaultAsset.renderPipelineEditorResources },
editorResourcesPath,
true);
}
}

bool IsHdrpAssetEditorResourcesCorrect()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ public void OnActivate(string searchContext, VisualElement rootElement)
{
m_ScrollViewPosition = Vector2.zero;
InitializeCustomPostProcessesLists();

var editorResources = HDRenderPipeline.defaultAsset.renderPipelineEditorResources;
if (!EditorUtility.IsPersistent(editorResources))
{
var editorResourcesPath = HDUtils.GetHDRenderPipelinePath() + "Editor/RenderPipelineResources/HDRenderPipelineEditorResources.asset";
HDRenderPipeline.defaultAsset.renderPipelineEditorResources = AssetDatabase.LoadAssetAtPath<HDRenderPipelineEditorResources>(editorResourcesPath);
}
}

void InitializeCustomPostProcessesLists()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
using UnityEngine.Experimental.GlobalIllumination;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.RenderGraphModule;
#if UNITY_EDITOR
using UnityEditorInternal;
#endif

namespace UnityEngine.Rendering.HighDefinition
{
Expand Down Expand Up @@ -563,10 +566,21 @@ void UpgradeResourcesIfNeeded()
HDRenderPipeline.defaultAsset.renderPipelineRayTracingResources = null;
}

var editorResourcesPath = HDUtils.GetHDRenderPipelinePath() + "Editor/RenderPipelineResources/HDRenderPipelineEditorResources.asset";
if (HDRenderPipeline.defaultAsset.renderPipelineEditorResources == null)
HDRenderPipeline.defaultAsset.renderPipelineEditorResources
= UnityEditor.AssetDatabase.LoadAssetAtPath<HDRenderPipelineEditorResources>(HDUtils.GetHDRenderPipelinePath() + "Editor/RenderPipelineResources/HDRenderPipelineEditorResources.asset");
ResourceReloader.ReloadAllNullIn(HDRenderPipeline.defaultAsset.renderPipelineEditorResources, HDUtils.GetHDRenderPipelinePath());
{
var objs = InternalEditorUtility.LoadSerializedFileAndForget(editorResourcesPath);
HDRenderPipeline.defaultAsset.renderPipelineEditorResources = objs != null && objs.Length > 0 ? objs.First() as HDRenderPipelineEditorResources : null;
}

if (ResourceReloader.ReloadAllNullIn(HDRenderPipeline.defaultAsset.renderPipelineEditorResources,
HDUtils.GetHDRenderPipelinePath()))
{
InternalEditorUtility.SaveToSerializedFileAndForget(
new Object[]{HDRenderPipeline.defaultAsset.renderPipelineEditorResources },
editorResourcesPath,
true);
}

// Upgrade the resources (re-import every references in RenderPipelineResources) if the resource version mismatches
// It's done here because we know every HDRP assets have been imported before
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using System;
using System.Collections.Generic;
using UnityEngine.Serialization;

#if UNITY_EDITOR
using System.Linq;
using UnityEditorInternal;
#endif
namespace UnityEngine.Rendering.HighDefinition
{
enum ShaderVariantLogLevel
Expand Down Expand Up @@ -97,7 +100,11 @@ internal HDRenderPipelineEditorResources renderPipelineEditorResources
// - cannot rely on OnEnable
//thus fallback with lazy init for them
if (m_RenderPipelineEditorResources == null || m_RenderPipelineEditorResources.Equals(null))
m_RenderPipelineEditorResources = UnityEditor.AssetDatabase.LoadAssetAtPath<HDRenderPipelineEditorResources>(HDUtils.GetHDRenderPipelinePath() + "Editor/RenderPipelineResources/HDRenderPipelineEditorResources.asset");
{
var objs = InternalEditorUtility.LoadSerializedFileAndForget(HDUtils.GetHDRenderPipelinePath() + "Editor/RenderPipelineResources/HDRenderPipelineEditorResources.asset");
m_RenderPipelineEditorResources = objs != null && objs.Length > 0 ? objs.First() as HDRenderPipelineEditorResources : null;
}

return m_RenderPipelineEditorResources;
}
set { m_RenderPipelineEditorResources = value; }
Expand Down