Я пытаюсь составить список для хранения всех игровых объектов.
Что бы я ни пытался, Unity сообщает мне, что я не могу использовать GetName, кроме как в основном потоке (я понятия не имею, куда я вызываю GetName, поскольку я только объявляю список). Ошибка:
UnityException: GetName можно вызвать только из основного потока.
Вот трассировка стека:
UnityException: GetName can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
UnityEngine.Object.GetName () (at \:0)
UnityEngine.Object.get_name () (at \:0)
UnityEngine.TextCore.Text.FontAsset.ReadFontAssetDefinition () (at \:0)
UnityEngine.TextCore.Text.FontAsset.GetCharacterInLookupCache (System.UInt32 unicode, UnityEngine.TextCore.Text.FontStyles fontStyle, UnityEngine.TextCore.Text.TextFontWeight fontWeight, UnityEngine.TextCore.Text.Character& character) (at \:0)
UnityEngine.TextCore.Text.FontAssetUtilities.GetCharacterFromFontAsset_Internal (System.UInt32 unicode, UnityEngine.TextCore.Text.FontAsset sourceFontAsset, System.Boolean includeFallbacks, UnityEngine.TextCore.Text.FontStyles fontStyle, UnityEngine.TextCore.Text.TextFontWeight fontWeight, System.Boolean& isAlternativeTypeface, System.Boolean populateLigatures) (at \:0)
UnityEngine.TextCore.Text.FontAssetUtilities.GetCharacterFromFontAssetsInternal (System.UInt32 unicode, System.Collections.Generic.List\`1\[T\] fontAssets, System.Boolean includeFallbacks, UnityEngine.TextCore.Text.FontStyles fontStyle, UnityEngine.TextCore.Text.TextFontWeight fontWeight, System.Boolean& isAlternativeTypeface, System.Boolean populateLigatures) (at \:0)
UnityEngine.TextCore.Text.FontAssetUtilities.GetCharacterFromFontAssetsInternal (System.UInt32 unicode, UnityEngine.TextCore.Text.FontAsset sourceFontAsset, System.Collections.Generic.List\`1\[T\] fontAssets, System.Collections.Generic.List\`1\[T\] OSFallbackList, System.Boolean includeFallbacks, UnityEngine.TextCore.Text.FontStyles fontStyle, UnityEngine.TextCore.Text.TextFontWeight fontWeight, System.Boolean& isAlternativeTypeface, System.Boolean populateLigatures) (at \:0)
UnityEngine.TextCore.Text.TextGenerator.GetEllipsisSpecialCharacter (UnityEngine.TextCore.Text.TextGenerationSettings generationSettings) (at \:0)
UnityEngine.TextCore.Text.TextGenerator.GetSpecialCharacters (UnityEngine.TextCore.Text.TextGenerationSettings generationSettings) (at \:0)
UnityEngine.TextCore.Text.TextGenerator.PrepareFontAsset (UnityEngine.TextCore.Text.TextGenerationSettings generationSettings) (at \:0)
UnityEngine.TextCore.Text.TextHandle.PrepareFontAsset () (at \:0)
UnityEngine.UIElements.UITKTextJobSystem+PrepareTextJobData.Execute (System.Int32 index) (at \:0)
Unity.Jobs.IJobParallelForExtensions+ParallelForJobStruct\`1\[T\].Execute (T& jobData, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at \:0)
Вот мой код (строки, закомментированные в IEnumerator, закомментированы, чтобы я мог попытаться выполнить отладку):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameManager : MonoBehaviour
{
public List targets;
private float spawnRate = 1;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
StartCoroutine(SpawnTarget());
}
IEnumerator SpawnTarget()
{
while(true)
{
yield return new WaitForSeconds(spawnRate);
// int index = Random.Range(0, targets.Count);
// Instantiate(targets[index]);
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... -exception
Unity C# — создание списка, вызывающего исключение ⇐ C#
Место общения программистов C#
-
Anonymous
1761180034
Anonymous
Я пытаюсь составить список для хранения всех игровых объектов.
Что бы я ни пытался, Unity сообщает мне, что я не могу использовать GetName, кроме как в основном потоке (я понятия не имею, куда я вызываю GetName, поскольку я только объявляю список). Ошибка:
UnityException: GetName можно вызвать только из основного потока.
Вот трассировка стека:
UnityException: GetName can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
UnityEngine.Object.GetName () (at \:0)
UnityEngine.Object.get_name () (at \:0)
UnityEngine.TextCore.Text.FontAsset.ReadFontAssetDefinition () (at \:0)
UnityEngine.TextCore.Text.FontAsset.GetCharacterInLookupCache (System.UInt32 unicode, UnityEngine.TextCore.Text.FontStyles fontStyle, UnityEngine.TextCore.Text.TextFontWeight fontWeight, UnityEngine.TextCore.Text.Character& character) (at \:0)
UnityEngine.TextCore.Text.FontAssetUtilities.GetCharacterFromFontAsset_Internal (System.UInt32 unicode, UnityEngine.TextCore.Text.FontAsset sourceFontAsset, System.Boolean includeFallbacks, UnityEngine.TextCore.Text.FontStyles fontStyle, UnityEngine.TextCore.Text.TextFontWeight fontWeight, System.Boolean& isAlternativeTypeface, System.Boolean populateLigatures) (at \:0)
UnityEngine.TextCore.Text.FontAssetUtilities.GetCharacterFromFontAssetsInternal (System.UInt32 unicode, System.Collections.Generic.List\`1\[T\] fontAssets, System.Boolean includeFallbacks, UnityEngine.TextCore.Text.FontStyles fontStyle, UnityEngine.TextCore.Text.TextFontWeight fontWeight, System.Boolean& isAlternativeTypeface, System.Boolean populateLigatures) (at \:0)
UnityEngine.TextCore.Text.FontAssetUtilities.GetCharacterFromFontAssetsInternal (System.UInt32 unicode, UnityEngine.TextCore.Text.FontAsset sourceFontAsset, System.Collections.Generic.List\`1\[T\] fontAssets, System.Collections.Generic.List\`1\[T\] OSFallbackList, System.Boolean includeFallbacks, UnityEngine.TextCore.Text.FontStyles fontStyle, UnityEngine.TextCore.Text.TextFontWeight fontWeight, System.Boolean& isAlternativeTypeface, System.Boolean populateLigatures) (at \:0)
UnityEngine.TextCore.Text.TextGenerator.GetEllipsisSpecialCharacter (UnityEngine.TextCore.Text.TextGenerationSettings generationSettings) (at \:0)
UnityEngine.TextCore.Text.TextGenerator.GetSpecialCharacters (UnityEngine.TextCore.Text.TextGenerationSettings generationSettings) (at \:0)
UnityEngine.TextCore.Text.TextGenerator.PrepareFontAsset (UnityEngine.TextCore.Text.TextGenerationSettings generationSettings) (at \:0)
UnityEngine.TextCore.Text.TextHandle.PrepareFontAsset () (at \:0)
UnityEngine.UIElements.UITKTextJobSystem+PrepareTextJobData.Execute (System.Int32 index) (at \:0)
Unity.Jobs.IJobParallelForExtensions+ParallelForJobStruct\`1\[T\].Execute (T& jobData, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at \:0)
Вот мой код (строки, закомментированные в IEnumerator, закомментированы, чтобы я мог попытаться выполнить отладку):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameManager : MonoBehaviour
{
public List targets;
private float spawnRate = 1;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
StartCoroutine(SpawnTarget());
}
IEnumerator SpawnTarget()
{
while(true)
{
yield return new WaitForSeconds(spawnRate);
// int index = Random.Range(0, targets.Count);
// Instantiate(targets[index]);
}
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79797282/unity-c-sharp-creating-a-list-causing-exception[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия