Example #1
0
        private static T FindOrLoadObject <T>(string pathName) where T : UObject
        {
            if (typeof(T) == typeof(UPackage))
            {
                return(FindOrLoadPackage(pathName) as T);
            }

            // If there is no dot, add a dot and repeat the object name.
            int packageDelimPos = pathName.IndexOf('.');

            if (packageDelimPos == -1)
            {
                int objectNameStart = pathName.LastIndexOf('/');
                if (objectNameStart != -1)
                {
                    pathName += "." + pathName.Substring(objectNameStart + 1);
                }
            }

            UClass unrealClass = UClass.GetClass <T>();

            if (unrealClass != null)
            {
                unrealClass.GetDefaultObject();// force the CDO to be created if it hasn't already
                T obj = UObject.LoadObject <T>(null, pathName);
                if (obj != null)
                {
                    obj.AddToRoot();
                }
                return(obj);
            }
            return(null);
        }
Example #2
0
        /// <summary>
        /// Returns the asset UObject if it is loaded or loads the asset if it is unloaded then returns the result
        /// </summary>
        /// <returns></returns>
        public UObject GetAsset()
        {
            if (!IsValid)
            {
                return(null);
            }

            UObject asset = UObject.FindObject <UObject>(null, ObjectPath.ToString());

            if (asset == null)
            {
                asset = UObject.LoadObject <UObject>(null, ObjectPath.ToString());
            }
            return(asset);
        }