#đŸ’»â”ƒcode-beginner

1 messages · Page 785 of 1

stone lake
#

you don't know any tutorials?

sour fulcrum
#

there's no magic link we have

stone lake
#

i mean thats fine i was just wondering, but thanks anyways

#

wait - I found this tutorial https://www.youtube.com/watch?v=ZEtKg9AyEJc . I'm not that knowledgeable on unity, but does it seem pretty substantial? That it might take a couple weeks to make at least?

Learn Unity 6 and C# by making a 2D game where you fight off enemies to protect a little girl. Timecodes below -👇

â–ș Complete RPG course - https://unityalexdev.com/rpg
â–ș Complete courses for beginners at - https://unityalexdev.com/#courses
â–ș I've opened a Discord server, join us!✊ - http://unityalexdev.com/discord

Important link...

▶ Play video
sour fulcrum
#

sure

polar acorn
#

You're probably not going to find a tutorial that solves all your problems. The idea is to learn from many sources and synthesize them into your own internal understanding of the process, rather than just parroting videos other people have made

stone lake
#

i guess i can just start with this and try adding stuff later

polar acorn
#

You don't need to vet a tutorial to see if it's "worth your time", just learn from anything you find

polar acorn
#

Well, you do need to learn "Stay the hell away from it" so there is still something to learn there

#

but yes, stick to actual sources that have actual knowledge

lyric igloo
solar hill
#

love ambiguous help requests with minimal context

lyric igloo
#

what more you need

slender nymph
#

pretty sure they just want someone to hold their hand and make it for them

polar acorn
#

If you want more than that, you will need to actually say what you want

solar hill
#

also you sent your code

#

but it has nothing to do with swords of any kind?

#

so the question is did you even attempt to do it on your own

#

or did you decide hey ill have these guys on discord do it for me?

lyric igloo
#

i have no idea how

solar hill
#

so break it down

lyric igloo
#

how do i do it without knowing how

solar hill
#

you learn how to do it

lyric igloo
#

yeah where

solar hill
#

first you break down your problem into multiple stages

#

the internet is a vast resource of knowledge

polar acorn
slender nymph
#

you need to start be deciding what it means to "use a sward"

polar acorn
#

"use a sward" isn't actionable

#

You need to actually describe it

lyric igloo
solar hill
lyric igloo
runic basalt
#

Is there a way to make decals only display on certain objects? I have a drill where I drill into a ceiling and I use a projector for the hole mark. But when the drill is still close up to the wall, the decal shows up on the drill. I created a rendering layer called decal, and set the projector's rendering layers to the decal layer, then I set the walls to have the decal rendering layer and no other objects have it. But still the decals are projected on other objects.

lyric igloo
slender nymph
# lyric igloo yeah ok ill go search it i did alrady but more deap ig

you need to break it down into actionable steps first because just searching "how to make ai use a sward" isn't going to get you anywhere. you need to first define what that means, break it down into smaller steps that you can research and put that knowledge together after researching how to complete each step

solar hill
slender nymph
# lyric igloo

this is literally the worst possible way to research anything

polar acorn
lyric igloo
#

yes you all right i will break it down and serch it like that thank you

magic temple
#

Hi, People

#

I need, Sanity with someone who can explain the "Coroutine" thing

#

Because I have a lot of issue with it, but I want to use that technologie, I know what is for (like a simulator of waiting for script) but I need a person how can help me with my bugs

wintry quarry
#

what bugs do you have?

#

Share your code and explain what's going on

polar acorn
# magic temple I need, Sanity with someone who can explain the "Coroutine" thing

Coroutines, once started with StartCoroutine, run like normal functions, one line at a time, top to bottom, until they hit a yield statement. That statement will then pause the coroutine and go back to the line after StartCoroutine and resume from there, until the yield instruction tells it to resume. The simplest yield instruction is yield return null, which will resume the coroutine from that spot next frame.

magic temple
# wintry quarry what bugs do you have?

Context : I create a Computer in my 2D isométric game, the player click on collider2D, and bom the prefab computer Spawn.

The thing is, its just a text thing right now, So, for that, I use Addressable for load a JSON file who have all the text that I will need.

And the principal issue is 2 thing, 1. A error that appair (but I thing I fix it somehow) that saw "I am Coroutine, I can't work because your gameobject (the computer) is Inactive !" But I try like, FORCE the unity to active it even I saw in my inspector the gameobject never been desactivate, but yea that thing break my mind, and its not the worse.

And Second one its the .. loss of my data, Like in my script That I will show you, I stock my text from JSON to a Variable that is a tab in a tab, and the thing that, its working good, but when Im outside of the function, its .. become null ? I will show you my code

wintry quarry
# magic temple Context : I create a Computer in my 2D isométric game, the player click on colli...

I create a Computer in my 2D isométric game, the player click on collider2D, and bom the prefab computer Spawn.
Nothing about this sounds like something that you would need a coroutine for.

A error that appair (but I thing I fix it somehow) that saw "I am Coroutine, I can't work because your gameobject (the computer) is Inactive !"
Can you share the code you used and the actual error message you saw?

loss of my data, Like in my script That I will show you, I stock my text from JSON to a Variable that is a tab in a tab, and the thing that, its working good, but when Im outside of the function, its .. become null ?
This sounds like a totally separate issue

magic temple
wintry quarry
#

ok yeah you'll need to show your code and any error messages you saw

swift crag
magic temple
#

I have 3 script, script one :

swift crag
#

you may be trying to start the coroutine on the computer prefab itself

magic temple
swift crag
#

and I'm pretty sure that prefabs do not count as being active

naive pawn
#

!code

radiant voidBOT
magic temple
#

ok wait

#

gonna try that

#

Here

#

I hope its work

#
  • In you will found Comparator, his job its to Compare Tags of GameObject, I create a Point and Click so I need to know what is for.
  • ComputerManager its the Brain of the Computer, he will be the bridge of the player input and the Computer.
  • ComputerTextManager a Brain too for Text of the Computer
magic temple
magic temple
polar acorn
magic temple
naive pawn
#

the one you have issues with

#

check its stacktrace and see which line it's coming from

magic temple
#

oh

naive pawn
#

then you can work backwards from there

magic temple
#

with the ComputerManager and the TextManagerComputer

#

From ComputerManager : IEnumerator Start()
{
yield return new WaitUntil(() => _ComputerTextManager.IsDataReady);

    _ComputerTextManager.Load(ComputerTextManager.Sections.Login, 0);
}
public void Launch()
{
    Start();
}
naive pawn
#

you aren't starting a coroutine there

magic temple
#

and the TextManagerComputer :
private void OnJsonLoaded(AsyncOperationHandle<TextAsset> handle)
{
if (handle.Status != AsyncOperationStatus.Succeeded)
{
Debug.LogError("Failed to load JSON Addressable.");
return;
}

    try
    {
        CurrentData = JsonConvert.DeserializeObject<SectionsData>(handle.Result.text);
        Debug.Log("JSON chargé avec succÚs !");
    }
    catch (System.Exception e)
    {
        Debug.LogError("JSON parsing error:\n" + e);
    }
}
swift crag
#

when you call Start(), you create an object: but just creating it does not do anything

naive pawn
#

please don't send these plaintext code snippets

#

it's.. very hard to read

magic temple
magic temple
swift crag
#

it has to get passed to StartCoroutine for Unity to start running through it

magic temple
#

Im paniking

naive pawn
magic temple
#

wait I will found it

naive pawn
#

show the actual error

#

you literally just do not have a coroutine there

swift crag
#

the only StartCoroutine in your code is on line 103 of ComputerTextManager.cs

swift crag
#

Importantly, if this object is a prefab (and not a copy of the prefab), this won't work

swift crag
#

you cannot start coroutines on the prefab's components

magic temple
#

Coroutine couldn't be started because the the game object 'Computer' is inactive!
UnityEngine.MonoBehaviour:StartCoroutine (System.Collections.IEnumerator)
ComputerManager:Launch () (at Assets/Script/BuildIn/Machine/Computer/Manager/ComputerManager.cs:92)
Comparator:MachineCompare (UnityEngine.Collider2D) (at Assets/Script/Interaction/Zone/Player/Comparator.cs:156)
PlayerControl:OnTrigger (UnityEngine.InputSystem.InputAction/CallbackContext) (at Assets/Script/Input Manage/Player/global/PlayerControl.cs:176)
UnityEngine.InputSystem.LowLevel.NativeInputRuntime/<>c__DisplayClass7_0:<set_onUpdate>b__0 (UnityEngineInternal.Input.NativeInputUpdateType,UnityEngineInternal.Input.NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate (UnityEngineInternal.Input.NativeInputUpdateType,intptr)

swift crag
#

ah, you've modified the code since sharing it

#

This is the same problem, though

magic temple
#

that is when I add a "StartCoroutine(Start())"

swift crag
#

You are calling Launch() on the prefab itself

#

the prefab object doesn't really exist

#

it acts like a deactivated game object

magic temple
#

oh

#

that suck

#

How- How I use it

#

If its "don't exist" ?

naive pawn
#

you need to be calling Launch on an instance of the prefab

#

the prefab does exist, but not in a scene

#

you need something in a scene

swift crag
#

I would expect this prefab to be placed in the scene

#

currently, your code does this...

#
public bool MachineCompare(Collider2D hit)
{
    GameObject obj = hit.GetComponentInParent<Transform>().gameObject; // met une sécurité ici

    if (obj.CompareTag("Computer"))
    {
        if (GetReferenceComputerManager())
        {
            _ComputerManager.Launch();
        }
        else
        {
            Debug.Log("Null!");
        }
            return true;
    }
    return false;
}
magic temple
swift crag
#

It's looking for an object in the scene, but then you just go to _ComputerManager and call Launch() on it

#

If ComputerManager is a "singleton" – something that there is only ever one copy of – you should instantiate it and then use the resulting copy

#

If it isn't – so each computer in your scene needs its own ComputerManager – then it should be attached to those computer objects

magic temple
#

So, Basicly, if I understand

#

My problem its that a Prefab its a ghost for Unity, and for that, I need to create a Gameobject that can be the Brain of the prefab ?

polar acorn
#

A prefab is a GameObject that lives in a file

#

Files cannot run coroutines

#

You need to run the coroutine on an object in the scene

magic temple
#

ok so

#

That I can fixe it, Thanks you

#

but I need a understanding with the last bug

#

The "Lost Value" of ComputerTextManager

#
    private void OnJsonLoaded(AsyncOperationHandle<TextAsset> handle)
    {
        if (handle.Status != AsyncOperationStatus.Succeeded)
        {
            Debug.LogError("Failed to load JSON Addressable.");
            return;
        }

        try
        {
            CurrentData = JsonConvert.DeserializeObject<SectionsData>(handle.Result.text);
            Debug.Log("JSON chargé avec succÚs !");
        }
        catch (System.Exception e)
        {
            Debug.LogError("JSON parsing error:\n" + e);
        }
    }
#

here to be precise, with CurrentData

#

I trying Debug.Log with it, and its show all my data, even when I modify the JSON

#

But when Im out of that function, the CurrentData Lose all his data

naive pawn
#

consider putting your description of the issue into a single message please

magic temple
polar acorn
magic temple
#
    private string Addressable { get; set; } = "MachineComputerText";
    private SectionsData CurrentData { get; set; }
    private Coroutine TypeCoroutine;
    private AsyncOperationHandle<TextAsset> handle;
    public bool IsDataReady => CurrentData != null;
naive pawn
#
  • are you assigning to it anywhere else
  • are you sure you're checking in the same instance
polar acorn
magic temple
magic temple
#

But in my unity, its losing

magic temple
polar acorn
# magic temple But in my unity, its losing

No, it isn't. Either you're overwriting it somewhere between when you set it and when you check it, or you're looking at a different object that didn't have OnJsonLoaded called on it

magic temple
#

My english its not my primary language, sorry if its bad-

naive pawn
magic temple
#

public bool Load(Sections section, int index, float delay = 1f, float delayPerChar = 0.03f)
    {
        if (CurrentData == null)
        {
            Debug.LogWarning("JSON not ready yet.");
            return false;
        }

        Data[] array = section switch
        {
            Sections.Starting => CurrentData.Starting,
            Sections.Login => CurrentData.Login,
            _ => null
        };

        if (array == null || array.Length == 0)
        {
            Debug.LogError($"Section {section} is empty or missing.");
            return false;
        }

        if (index < 0 || index >= array.Length)
        {
            Debug.LogError($"Index {index} out of range for {section}. Length={array.Length}");
            return false;
        }

        if (TypeCoroutine != null)
        {
            Debug.Log("Il est nulle le Coroutine");
            StopCoroutine(TypeCoroutine);
        }

        TypeCoroutine = StartCoroutine(
            TypewriterEffectWithDelay(array[index].text, delay, delayPerChar)
        );

        return true;
    }

Here is the only function that use CurrentData

naive pawn
#

and where do you call OnJsonLoaded

magic temple
#

in the same file

naive pawn
#

that doesn't help

magic temple
#

.. Like, upper ? On the Awake() ?

#

ooh

polar acorn
naive pawn
#

what method chain links OnJsonLoaded to Load

magic temple
#

yea, in the Awake()

naive pawn
#

no, you aren't calling it there.

magic temple
polar acorn
#

Where are you calling OnJsonLoaded and what object are you calling it on?
Where are you calling Load and what object are you calling it on?

magic temple
polar acorn
#

What calls Load

naive pawn
#

@magic temple what info is telling you that CurrentData is gone? the JSON not ready yet. log is triggering?

naive pawn
magic temple
#

Here is the full script (modify for discord) :

    private void Awake()
    {
        handle = Addressables.LoadAssetAsync<TextAsset>(Addressable);
        handle.Completed += OnJsonLoaded;
    }

    private void OnJsonLoaded(AsyncOperationHandle<TextAsset> handle)
    {
        if (handle.Status != AsyncOperationStatus.Succeeded)
        {
            Debug.LogError("Failed to load JSON Addressable.");
            return;
        }

        try
        {
            CurrentData = JsonConvert.DeserializeObject<SectionsData>(handle.Result.text);
            Debug.Log("JSON chargé avec succÚs !");
        }
        catch (System.Exception e)
        {
            Debug.LogError("JSON parsing error:\n" + e);
        }
    }

    public bool Load(Sections section, int index, float delay = 1f, float delayPerChar = 0.03f)
    {
        if (CurrentData == null)
        {
            Debug.LogWarning("JSON not ready yet.");
            return false;
        }

        Data[] array = section switch
        {
            Sections.Starting => CurrentData.Starting,
            Sections.Login => CurrentData.Login,
            _ => null
        };

        if (array == null || array.Length == 0)
        {
            Debug.LogError($"Section {section} is empty or missing.");
            return false;
        }

        if (index < 0 || index >= array.Length)
        {
            Debug.LogError($"Index {index} out of range for {section}. Length={array.Length}");
            return false;
        }

        if (TypeCoroutine != null)
        {
            Debug.Log("Il est nulle le Coroutine");
            StopCoroutine(TypeCoroutine);
        }

        TypeCoroutine = StartCoroutine(
            TypewriterEffectWithDelay(array[index].text, delay, delayPerChar)
        );

        return true;
    }
}
polar acorn
magic temple
polar acorn
#

I didn't see that bit

magic temple
naive pawn
#

ComputerManager.cs:88

magic temple
#

here

naive pawn
polar acorn
#

Oh there's multiple tabs

#

I didn't even notice

magic temple
#

hehe

#

I put a lot of that thing that I call 'Dog cage'

#

like a security thing

polar acorn
#

Okay, so _ComputerTextManager is the object that runs Load. Which object is that referring to?

naive pawn
#

have you tried checking CurrentData after you load it

naive pawn
magic temple
polar acorn
naive pawn
#

well, obviously not empty

polar acorn
#

the one that doesn't exist in the scene

#

and therefore cannot run Awake

naive pawn
#

in the prefab or in the prefab instance?

polar acorn
#

which means it can't have had OnJsonLoaded called on it

magic temple
#

wait wait

#

One thing

naive pawn
magic temple
#

When I start the game, the prefab charge, and the Text from the JSon are loaded in my view of player

#

but when I trying like, control the text, the CurrentData say to me that its null

#

that is the issue

naive pawn
#

this doesn't answer any of our questions

magic temple
#

Ah-

#

SOrry-

magic temple
polar acorn
naive pawn
magic temple
#

like its a multiple hierachie with parent

#

A group ?

naive pawn
#

that's unrelated

magic temple
#

I terribly sorry

naive pawn
#

is it in an instance of the prefab, in a scene

magic temple
#

Like-

#

In the Scene when load ?

#

Load the prefab, not the function

polar acorn
#

The prefab file, and the instance in the scene are not the same object

#

They are two different objects that both have this script on them

#

You are calling OnJsonLoaded on one of them, and then checking the other one to see if the data is set

#

And, since it's a different object, that one doesn't have CurrentData set

magic temple
#

I gonna show you I think

#

here, Computer have the ComputerManager Script, annd ComputerTextManager have the .. computerTextManager

naive pawn
#

crop less

#

this does not contain the info asked

magic temple
#

.. Im so confuse

naive pawn
#

we are asking whether or not the object is in the scene

#

we don't particularly care about the specific hierarchy

magic temple
#
public bool MachineCompare(Collider2D hit)
    {
        GameObject obj = hit.GetComponentInParent<Transform>().gameObject; // met une sécurité ici

        if (obj.CompareTag("Computer"))
        {
            if (GetReferenceComputerManager())
            {
                _ComputerManager.Launch();
            }
            else
            {
                Debug.Log("Null!");
            }
                return true;
        }
        return false;
    }
naive pawn
#

that code is not relevant

#

do you have instances of these components in the scene or not

magic temple
#

Say me a exemple

naive pawn
#

do you know what a scene is

polar acorn
#

Is there an object with a ComputerTextManager component in the scene

magic temple
#

ye

naive pawn
#

that is the main cause of your issues

polar acorn
#

Because Awake does not run on prefabs

magic temple
naive pawn
#

notlikethis what are you even looking at

magic temple
#

If I can't have the information, how I see it

polar acorn
#

And I have no idea what

#

because I cannot see what you see

#

and you have to actually provide information

naive pawn
#

jesus christ just take a screenshot of your entire unity window

magic temple
naive pawn
#

no

solar hill
#

theres also no voice chats here

magic temple
#

Im not here to lie, im seeing what im seeing

naive pawn
#

maybe you didn't knowingly lie, but something you've said is wrong

magic temple
#

When I click on the trigger, the prefab spawn and the text from the json its loaded

naive pawn
#

what are you clicking on

magic temple
naive pawn
#

an instance of the prefab in the scene? or what exactly?

#

that gives me no info at all

magic temple
#

wait

#

I will show you

#

that little block its my Collider

#

he have a tag

#

and Comparator will .. compare that tag

#

if the tag its correct, the prefab are call

#

Do you want that I Screen Share ?

naive pawn
#

no

magic temple
#

aww

naive pawn
#

and to be clear, the computer isn't inside the canvas or the maincamera, right

magic temple
#

Oh

#

im

#

Well, the prefab have a canvas, but its not IN a canvas

naive pawn
#

god

magic temple
#

Im new at Unity, Im trying-

naive pawn
#

the computer isn't inside the object inside your scene named "Canvas" or the object named "MainCamera", correct?

magic temple
#

yes

naive pawn
magic temple
#

" but its not IN a canvas" and I think I make it thew

naive pawn
# magic temple yes

cool, then we've established one of the things you've said is correct - the computer is not in the scene. there does not exist a Computer instance, which you need to be able to do things in unity

#

that is your main issue

magic temple
#

alright, when, why use a prefab ?

naive pawn
#

when you want to use a gameobject as an asset, one you can reuse in multiple places, and you can modify that asset and have that change propagate to all its instances and variants

magic temple
naive pawn
#

no clue what you're referring to at this point tbh

#

is the prefab being instantiated from some other object?

#

if not,

when the prefab is activated and put on the scene
this just isn't happening.

#

you also haven't really shared what exactly you're looking at in the gameview

magic temple
naive pawn
naive pawn
magic temple
#

here a video

naive pawn
#

ok, so you have a Computer(clone) there. sounds like that's an instance of your Computer prefab

#

probably something else is instantiating it

#

yeah ok, this is starting to make sense.

magic temple
naive pawn
#

well that's obviously not correct

magic temple
#

enlighten me

naive pawn
#

right now you have 2 instances of the ComputerManager/ComputerTextManager.

one in the prefab, one created later in the scene, at runtime.

the one created in the scene is handling itself. the ComputerManager.Start coroutine is being executed, ComputerTextManager.Awake is being run, etc.

the prefab one is getting its ComputerManager.Start called separately or something, maybe through Launch (which probably should not exist), there's that weird AutoAssignAssetReferences in Comparator. you definitely don't need anything like that

magic temple
#

AutoAssignAssetReferences its a Script that I create to Found all my forgetin References, its a security for people that work in my project

naive pawn
#

sounds like something that would only cause problems tbh

#

why does something DDOL need to persistently reference something in a specific scene anyways

magic temple
#

what

#

how do you do it?

naive pawn
#

with serialized references or with singletons where that makes sense

#

something DDOL like that wouldn't be written for something in a specific scene anyways

#

and i don't see why you'd instantiate it at runtime, why not just have it in the scene

magic temple
#

Because I'm changing scenes, and I want to keep important game objects such as Player or bluidin.

naive pawn
#

that doesn't really change any of what i said

magic temple
#

Well, be more specific.

naive pawn
#

ive been pretty specific

#

what you said simply is not relevant to what i said

#

is Comparator specific to this scene, or is it used for many scenes?

magic temple
#

Used for many scenes

#

The player will go through the scenes for various reasons, so in order to know what it's used for and where it clicked, I need scripts that won't get lost.

naive pawn
magic temple
#
 public async UniTask<bool> Zone(Collider2D hit)
 {
     if (!hit)
     {
         return false;
     }

     GameObject obj = hit.GetComponentInParent<Transform>().gameObject;

     if (obj.CompareTag("GreenZone"))
     {
         return true;
     }

     if (obj.CompareTag("RedZone"))
     {
         return false;
     }

     if (obj.CompareTag("InteractiveZone"))
     {
         return await _InteractiveZoneController.OnInteractiveZone(hit);
     }

     if (UnityDebugLog)
     {
         Debug.LogWarning("[Comparator](Zone) Aucun tag reconnu.");
     }

     return false;
 }
#

Like here, its for the scene Outside, Dortory1, Village..

#

I'm trying to limit scripts, not give each scene its own script, which kills performance.

#

But what's the point? Why are we having this discussion? It won't help you understand my problem.

naive pawn
naive pawn
magic temple
naive pawn
#

why not just have each machine manage itself

#

that would be much simpler

magic temple
naive pawn
#

efficiency does not matter at this scale

magic temple
naive pawn
#

that's a very common beginner pitfall, premature optimization will only give you more workload for nonexistant results

magic temple
naive pawn
#

optimize when you have issues

#

make it an interface even, IInteractable, check if you've clicked an IInteractable in the player, call the Interact method
the machine implements IInteractable and plays the text when you interact with it, or whatever.

naive pawn
# magic temple Not for me

computers are fast. you could have 5000 comparators in the scene and probably not notice any difference at all

slender nymph
# magic temple Not for me

if you're looking for peak efficiency then don't make a game at all. it's more efficient to imagine you are playing a game because that doesn't use any of your computer's resources and can run at a framerate that matches the speed of your thoughts

naive pawn
#

you have other issues to worry about at this stage

#

make something work before making it good. and making it simple to work with is a very important step to making it work

brazen heart
#

Hey guys I'm having a few issues with inputs in Unity
I'm really new to the engine so forgive me if I don't understand some things
Basically I have a button and when I click it I have a line to simply log it in the console but no matter what I've tried, nothing works

magic temple
#

I don't think we share the same way of thinking. My goal is to rack my brains, understand the very core of Unity, try to understand the issues, and that's what fascinates me, not making infinite loops and hoping no one notices.

naive pawn
#

simple code makes issues easy to understand. you aren't trying to understand unity here, you're trying to understand issues created from your own convoluted code

slender nymph
naive pawn
#

also make sure you've added that component

magic temple
#

Is your goal to give your future self more work and headaches and call it “pro dev”? I'm taking things into account right now, as any good developer should.

solar hill
#

youre giving yourself more work and a headache now

#

so what are you really accomplishing here

magic temple
naive pawn
#

ok, so design your systems to be easy to work with

solar hill
#

even if you created perfect systems and configurations now you will still have other challenges down the line

#

like this is just the nature of development

brazen heart
slender nymph
brazen heart
solar hill
#

sometimes you gotta relax and think "we will burn that bridge when we get there"

magic temple
naive pawn
#

when did i say that

slender nymph
solar hill
#

also what do you mean sacrificing the player

magic temple
solar hill
naive pawn
brazen heart
solar hill
#

love the implication that a player would give a shit if a system they dont know about in a game they are playing isnt perfectly optimal

#

just a reminder clair obscur just won game of the year and it runs like shit

#

people dont really care anymore

#

the bar for performance is so low it might as well be a chalk drawing

magic temple
# solar hill also what do you mean sacrificing the player

That's the whole problem with developers, and I'm not the only one saying it: you make life easier for yourselves rather than improving the player experience. Personally, I try to rack my brains as much as possible to offer a game that can run on even the worst PCs, rather than expecting players to have a good computer.

naive pawn
polar acorn
#

The fastest possible code is one that doesn't run

solar hill
naive pawn
slender nymph
# magic temple Dude, do you need psychological help?

i'm being realistic. you are doing things out of order in some harebrained attempt at making yourself need to work less later, when you are making your workload now even larger than what it would have been overall if you started with "make it work" before "make it fast"
the order should be make it work -> make it good -> make it fast
otherwise you're going to run into issues now while attempting to make it fast before it even works, then when it isn't good and you need to redesign you need to do even more work

brazen heart
solar hill
#

youre also optimizing your game for the 1% of the 1% which isnt good

magic temple
polar acorn
slender nymph
naive pawn
solar hill
#

or are you just not listening

polar acorn
#

Considering how hard we had to explain the difference between a prefab and an instance, you probably shouldn't be worried about efficiency.

slender nymph
#

and the buttons are attached to the canvas, right?

brazen heart
#

Yeah

magic temple
slender nymph
naive pawn
brazen heart
polar acorn
naive pawn
polar acorn
#

What data are you comparing it to?

slender nymph
# brazen heart screenspace

and your canvas has a Graphic Raycaster on it, yes?
and the images on the buttons do not have "Raycast Target" unchecked?

solar hill
#

also i dont think you are being very fair to the people who were helping you for the past hour

polar acorn
# brazen heart Yeah

Do the buttons visibly respond to the mouse? By default they should change color when you hover or press them

brazen heart
slender nymph
#

oh wait, sorry had that reversed it must be checked

magic temple
naive pawn
#

@magic temple literally everyone here has been a beginner before.
many of us have encountered many of the issues we're referring to. this advice has been from collective experience

brazen heart
polar acorn
brazen heart
solar hill
#

you immediately become hostile at the slightest bit of valid criticism

brazen heart
#

I have a graphic raycaster in the canvas and both are checked

slender nymph
naive pawn
polar acorn
magic temple
naive pawn
#

you have broken code

#

what do you mean you're on the optimization phase

#

you need to make it work first

polar acorn
magic temple
#

Avoided addressable, doing something more “the hard way,” without prefab, without all those coroutines... In short, yes, I went through those steps, and now I'm improving what I've created. Why is it such a big deal to you?

naive pawn
#

....what?????

#

i gave you advice on how to improve your code

brazen heart
magic temple
naive pawn
#

if you consider what you're doing now to be optimization, then yes

magic temple
magic temple
#

Like, People

#

Please, why are we even talk about it

polar acorn
#

I think it's a URP thing?

magic temple
#

My question here is, Why a prefab is 'enable' that has been answer, thanks you for that

solar hill
#

come again?

magic temple
#

and, why I have acces to my JSON even the Awake of my prefab its not suppose to be activate ?

naive pawn
#

i gave you advice on how to improve your code, and you've been aggressively denying it because it would make performance worse
that's just not how you should be working

polar acorn
#

This is impossible, I can't keep dealing with someone who is belligerent as well as having a language barrier

naive pawn
magic temple
magic temple
polar acorn
#

It's the same thing I've said as well. The one that you're loading the JSON on and the one you're trying to read it from are different instances

magic temple
naive pawn
#

that's not a question

magic temple
#

Good point

naive pawn
#

you have a Computer prefab (as an asset, in the project) and a Computer prefab instance (in the scene)

both of those each have their own ComputerManager/ComputerTextManager

polar acorn
#

The prefab file and the instance in the scene are not the same object

#

I cannot stress this enough

#

They're two different instances

#

If you do something to one of them, the other one is unaffected

magic temple
#

So, Computer, which is cloned on stage and includes my script, the ComputerManager and ComputerTextManager, ComputerManager can have its awake activated, but not ComputerTextManager?

naive pawn
#

no, the ones in your scene are active, the ones in the prefab are not

magic temple
#

... Well, here is, my problem

#

the core even, My Cloned one say to myself, that he is inactif

#

and losing his own data

#

The Cloned one, the one in the scene

naive pawn
#

that's not what happened, no

#

ive already explained what's most likely happening

magic temple
#

yea and you say that ComputerManager its awake, but not ComputerTextManager

#

if im correct

naive pawn
#

you are not

#

i just corrected you

naive pawn
#

yes, and in my initial explanation as well

magic temple
#

" right now you have 2 instances of the ComputerManager/ComputerTextManager.

one in the prefab, one created later in the scene, at runtime.

the one created in the scene is handling itself. the ComputerManager.Start coroutine is being executed, ComputerTextManager.Awake is being run, etc.

the prefab one is getting its ComputerManager.Start called separately or something, maybe through Launch (which probably should not exist), there's that weird AutoAssignAssetReferences in Comparator. you definitely don't need anything like that " here ?

naive pawn
#

what else would i be referring to

zenith cypress
polar acorn
magic temple
#

I mean, right now Im tired, like, really tired, and if I

#

if I say someting bad, im sorry

naive pawn
#

i'm irritated because you seem to be intentionally obtuse right now

magic temple
#

Well, its not my objectif

#

I want just to fix a missunderstanding of mine

#

Still, thanks you for your time

#

I will, try to make it not a prefab, or something

#

My excuse, have a good day

naive pawn
#

sounds like you do want it to be a prefab here, considering you wanted more computers

#

you just need to treat it correctly

magic temple
#

But, Im searching how to do it

#

but im sure I will found out

old skiff
#

why could this code not work

naive pawn
#

you tell us

#

what's the issue

old skiff
#

its suppost to make you move but i just fly or makeweird movements

polar acorn
#

Try logging w and see if it's doing what you expect

slender nymph
#

did your keyboard stop working partway through naming these variables? or is there some reason they have names like we and w that don't appear to actually mean anything?

old skiff
#

uh well i was lazy and im just testing my skills

slender nymph
#

coding skills including making your code readable

old skiff
#

but it aint working why\

slender nymph
#

try logging some useful information, like digi suggested instead of just logging the word "moving" since that doesn't actually tell you anything

swift crag
#

I don't see any movement happening at all in that example

old skiff
#

nvm i think its because i forgot to make speed higher and rigidbody not get effectedby objects changing it rotation

#

i mean freese rotation

dry sun
naive pawn
#

it toggles the input mode between insert and replace

#

also configure your ide

#

!ide

radiant voidBOT
dry sun
willow iron
#
{
    public Produce product;
    public GameObject screen;
}
public class SupplyPurchaser : MonoBehaviour
{
    public Storage produceHandler;
    public GameObject listingPrefab;
    public GameObject scrollView;

    public void Start()
    {
        Initialize();
    }

    private void Initialize()
    {
        Listing[] listing = new Listing[produceHandler.produce.Length - 1];
        for (int i = 0; i < produceHandler.produce.Length; i++)
        {
            Debug.Log(i);
            listing[i].product = produceHandler.produce[i];
            listing[i].screen = Instantiate(listingPrefab, scrollView.transform);
            listing[i].screen.name = listing[i].product.itemName;
            listing[i].screen.GetComponent<PurchaseAmountHandler>().Initialize(listing[i].product);
        }
    }
}```
according to unity, line 34 `listing[i].product =  produceHandler.produce[i];`  has the following error: Object reference not set to an instance of an object

i imagine im just not understanding how classes work, this is my first time really messing with them
coral crater
#

aplogies if this isn't exactly the right channel for this - I'm looking to do something adjacent to A* pathfinding for my game. However, I can't really find a tutorial which covers pathfinding for a non-grid based non-top-down scenario. all I need really is a way for each of these green rectangles the know who their neighbouring rectangles are so they know how to calculate a path towards a destination, e.g. the character is at the red star, and now needs to go to the red cross. Is there an obvious way of setting up a "web" or these neighbouring boxes/grids/waypoints etc? considering the fact that some areas will be more complex and forking than this one

the first thing I thought of when it came to implementing this was to actually create invisible rectangle gameobjectthat do overlap physically, so they can check for a physics overlap to know where their neighbours are when a new path is being looked for, but that sounds kinda resource intensive?

tl;dr, best way to make a custom grid where each component knows what's neighbouring it?

eternal needle
polar acorn
nocturne goblet
#

Is this a good tiling script using UnityEngine;

[ExecuteInEditMode]
public class IndividualSideTiler : MonoBehaviour
{
[System.Serializable]
public struct SideSettings
{
public Vector2 tiling;
public Vector2 offset;
}

public SideSettings top = new SideSettings { tiling = new Vector2(1, 1) };
public SideSettings bottom = new SideSettings { tiling = new Vector2(1, 1) };
public SideSettings front = new SideSettings { tiling = new Vector2(1, 1) };
public SideSettings back = new SideSettings { tiling = new Vector2(1, 1) };
public SideSettings left = new SideSettings { tiling = new Vector2(1, 1) };
public SideSettings right = new SideSettings { tiling = new Vector2(1, 1) };
#

private MeshFilter meshFilter;
private Mesh originalMesh;
private Vector2[] baseUVs;

void OnEnable()
{
    meshFilter = GetComponent<MeshFilter>();
    if (meshFilter != null && meshFilter.sharedMesh != null)
    {
        // Store the original mesh UVs so we don't "stack" tiling every frame
        originalMesh = meshFilter.sharedMesh;
        baseUVs = originalMesh.uv;
    }
}

void Update()
{
    if (meshFilter == null || baseUVs == null) return;

    ApplyCustomUVs();
}

void ApplyCustomUVs()
{
    Vector3[] normals = originalMesh.normals;
    Vector2[] newUVs = new Vector2[baseUVs.Length];

    for (int i = 0; i < newUVs.Length; i++)
    {
        Vector3 n = normals[i];
        SideSettings settings = front;

        // Logic to find which side is which based on direction
        if (Mathf.Abs(n.y) > 0.5f) settings = n.y > 0 ? top : bottom;
        else if (Mathf.Abs(n.x) > 0.5f) settings = n.x > 0 ? right : left;
        else if (Mathf.Abs(n.z) > 0.5f) settings = n.z > 0 ? front : back;

        newUVs[i] = new Vector2(
            baseUVs[i].x * settings.tiling.x + settings.offset.x,
            baseUVs[i].y * settings.tiling.y + settings.offset.y
        );
    }

    // Apply the modified UVs to a unique instance of the mesh
    meshFilter.mesh.uv = newUVs;
}

}

silk night
#

Eh why is that link in here? 😄

brazen heart
#

Does anyone know how I can fix this error? I can't seem to find this option in the inspector

brazen heart
#

I found it thx

#

Ok now instantiating the object itself doesn't seem to work
I've tested that this runs but no object gets instantiated

slender nymph
#

make sure it isn't actually being destroyed immediately because this will instantiate the object

#

also, I know it isn't a compile error because there's the implicit cast and it will make no difference here, but you probably want to be using UnityEngine.Quaternion rather than Unity.Mathematics.quaternion unless you actually know why you would want to be using the latter rather than the former

north kiln
brazen heart
#

It's zero based right?

#

If there were only 1 object and I rolled a 1 wouldn't that be outside of the array?

#

But yeah I got the thing to work

slender nymph
brazen heart
#

Oh wait yeah I forgot about that

#

thx

sweet meadow
#

character controller:

slender nymph
#

!code but also if the error is only in the unity console that means you haven't saved this code

radiant voidBOT
sweet meadow
#

logic manager:

#

ok, it lets me run the game now, but i can still flap after death and this error appears:

slender nymph
#

and what is line 27 of Logic.cs

sweet meadow
slender nymph
#

then bee is not assigned, make sure you've dragged the reference into the inspector since that variable is serialized

sweet meadow
#

ok

#

there's no error message now, but it still dosn't work, im guessing i have to specify the object and then the script attached to it?

slender nymph
#

you likely have more than one Logic component in the scene and the other one, which is the one being found with that FindGameObjectWithTag call, doesn't have it assigned. you should do two things here:

  1. remove extra Logic components if you only need the one
  2. serialize your logic variable and drag the reference in like you've done for these other variables instead of relying on a GameObject.FindXXX call
tired python
#

would something like this work?

#

colliders having the same layer will def collide with each other

slender nymph
#

that doesn't change what i said. search the hierarchy using t:Logic and you'll see at least two Logic components in the scene

void zodiac
slender nymph
#

!code

radiant voidBOT
void zodiac
#

wait do i pastye on link?

#

lmk if it doesnt work

slender nymph
#

okay now look at your Update method. what if statement do you think is being entered with this as your layermask

void zodiac
#

should i put player and ground to default?

slender nymph
#

they should be whatever layer the objects you are trying to detect are on

void zodiac
#

wait how would I get more of my layers as an option?

#

thank u sm for ur help btw

slender nymph
void zodiac
#

like how would i make it pop up as an option where everything is rn

#

ill take a pic

slender nymph
#

it's a dropdown menu that will open up to list all of the layers

void zodiac
slender nymph
#

yes, those are all of the existing layers that you have

void zodiac
#

where would i see whats in each layer doe

#

sorry im rly new to this

slender nymph
#

look at the object(s) you want to detect and look at what layer you've put them on

void zodiac
#

OMG I SEE IT

#

TGHANK YOPU*

slender nymph
#

ideally you'd create a new layer specifically for the player and put it on that layer, then only include that layer for your "what is player" layermask

#

same for ground, really (although this isn't a strict requirement like the above would be)

#

and you definitely do not want those things on the same layer, otherwise you'll be detecting the ground as the player

sweet meadow
#

how do i make this work? do i say 'if (Collision2D.tag == ("Pipe")' instead?

slender nymph
#

use the compare tag method, not string equality. but also you need to get the tag of the collider/gameObject that is being collided with which the Collision2D object has a reference to

#

you were so close before when you posted in the wrong channel, you just weren't using the correct method name

sweet meadow
#

how would i write that

slender nymph
#

go back to the code you had before and change it to the correct method name

void zodiac
#

i made 2 layers for player and monster, but it's still not moving UnityChanThink

#

Do i need a layer for monster aswell maybe?

slender nymph
#

what layer is the ground on

#

i mean the actual object in the scene, not the layermask variable

void zodiac
#

it's on ground it is untagged doe

slender nymph
#

right, so if the ground is on the Ground layer, and you are detecting the player by checking if anything is within range on the Ground layer, which of the three if statements in your Update method do you think is currently true?

void zodiac
#

omg i cant believe i did that

cosmic dagger
tired python
rancid berry
#

hey can someone PLEASE HELP ME ive been on the internet for about some time now about 3 months looking for SOMETHING to help me learn C# and the fact is, theres so much i dont know where to put my time to learn. I was watching sebatian Leauge videos but he goes a bit fast and often i rewatch videos and feel stupid. My name is SirSurf and if anyone can help a beginner that would help. I want to create games in Unity and learn how to do C# so i can later do it as a game dev in the future and this is something that i really want to spend time on so if someone could give me a course because thats what i was looking for before and it was alright and so did videos and i came here to also ask questions about things.... yeah... sorry for the rant.....notlikethis

slender nymph
#

there are beginner c# courses pinned in this channel

rancid berry
#

i feel so lost

tired python
#

and start coding, not just watching videos

cosmic dagger
rancid berry
tired python
cosmic dagger
#

@tired python Placing GameObjects on a layer does not automatically filter them during collisions . . .

slender nymph
#

yes it does (provided you call it on the correct type of object)

sweet meadow
#

i call it on 'collider' right?

tired python
#

maybe you are thinking of a specific scenario or something? i don't quite get it

slender nymph
cosmic dagger
#

If you use trigger or collision methods, comparing layers is the fastest option, TryGetComponent is slower (but still fast) and gives you the component of the object has one . . .

rancid berry
#

can all fundementals of C# be applied in other things? a problem i find is how to use code creativly but i dont think you guys are like a dictionary or google so if you cant answer that its fine

sweet meadow
slender nymph
#

several things wrong here, for one, this isn't even attempting to use CompareTag. for two, you are doing this on a Collision2D not a Collider2D. those are different types of objects

cosmic dagger
slender nymph
#

yes it does. it's Collision2D that doesn't

cosmic dagger
#

And you didn't even use CompareTag . . .

tired python
sweet meadow
slender nymph
# sweet meadow yea that was the old code

now go back to the even older code where you asked what you did wrong and it was pointed out you had the wrong method name. then just use the right method name
which is exactly what i already told you to do but you just didn't for some reason

cosmic dagger
# sweet meadow

You're just adding things randomly now. You need to access a field or property that has the CompareTag method . . .

sweet meadow
#

it works now

#

srry

cosmic dagger
tired python
sweet meadow
#

is there an easy way to check for both collision and trigger enter?

#

in the same statement

cosmic dagger
slender nymph
tired python
sweet meadow
slender nymph
#

if your logic is exactly the same in both of them you could just have each of them call the same method though (passing relevant data like the collider entered/collided with)

slender nymph
# sweet meadow what i mean is can i check for both simultaniously

not those methods, no. because, again, they are separate methods. you could use physics queries to check for overlapping colliders and do manual collision checking, but that's a lot of work and the right thing to do depends entirely on what you are actually trying to accomplish

tired python
#

you know what, i will implement what i am tryna do, and then post it to you later, @cosmic dagger

cosmic dagger
tired python
cosmic dagger
#

You need a filter to find out if the collided GameObject is the one you are looking for. There are multiple ways to filter . . .

  • compare layers
  • check Component
  • compare tags
#

Anytime you have a collision, whether using a trigger/collision method, the Cast methods, or the Overlap methods, you need a filter to check the collided object(s) . . .

tired python
#

suppose i have two different GameObjects one of which has a kinematic collider, while the other one has a static collider. If i were to rb.useFullKinematicContacts = true; on the GameObject having the static collider, would it recognise collisions with the GameObject having the kinematic collider?

#

cus on trying it out, i am having to enable the Use Full Kinematic Collision on the GameObject having the Kinematic collider, and only then is the collision being detected...

#

said GameObjects in question

slender nymph
wintry quarry
#

This is only used when the bodyType is set to RigidbodyType2D.Kinematic.

tired python
wintry quarry
slender nymph
#

are you certain that wasn't setting it on the kinematic body?

tired python
#

and it stopped working after that

slender nymph
#

is there even a specific reason this object has a rigidbody on it if you want it to be static anyway? i get that under very specific circumstances that would be necessary, but it doesn't seem like it is here

tired python
slender nymph
#

what does that have to do with having a static rigidbody?

tired python
#

the dragon don't move

#

and similarly, the collider doesn't

slender nymph
#

right, which is why i'm asking why it has a rigidbody at all

tired python
#

cus collision checks can't happen with just a collider

slender nymph
#

making the rigidbody static is exactly the same as having no rigidbody when it comes to collision detection

tired python
#

💀

#

wait, so a GameObject with just a collider in it which is static triggers OnCollisionEnter2D?

slender nymph
#

no, only a dynamic rigidbody will cause those messages

hot wadi
tired python
#

oh, well in that case, the dragon does need the rb cus it has a script attached to it which checks for collision and blasts it away

slender nymph
slender nymph
tired python
#

well, i don't want the other GameObject's script to have more lines of code

slender nymph
#

nobody said that was necessary. all i'm saying is that the static rigidbody on this object is doing literally nothing at all and can be removed

tired python
#

WAIT A SEC

slender nymph
#

and object can still receive a collision message from a dynamic rigidbody even if it doesn't have one itself. it's only the dynamic rigidbody that is actually sending that message

tired python
#

the other gameobject sends the msg to the static gameobject

slender nymph
#

that is how physics messages work, yes

hot wadi
#

If u are talking about trigger, static can still receive it

tired python
slender nymph
#

that is not in question here. and is, in fact, pretty much what i have been saying this entire time. the dynamic rigidbody is sending the collision message to the static collider

#

or i guess maybe it's a kinematic body with full contacts enabled. either way though, the non-static body is sending the message to both objects

tired python
#

naw

#

aight

#

oh wait, nvm, it won't work, cus i am already using a collision check to do something else, i would need to check for layer in that case i guess

sweet meadow
#

how would i teleport an object to say, 0 -10 0?

slender nymph
#

assign its transform.position to that

sweet meadow
#

something like this?

slender nymph
#

you should do some beginner c# courses to learn how the language works. there are some excellent ones pinned in this channel

sweet meadow
#

ok

#

rb.transform.position = new Vector3(0, -10, 0); ?

#

yippie

slender nymph
#

although if you are doing this for a rigidbody you'd want to set the rigidbody.position rather than the transform's position

#

you should still go through some beginner c# courses to actually learn how the language works instead of just guessing though

tired python
#

@slender nymph it does return a nre

slender nymph
#

show exactly where you are getting this NullReferenceException, because a destroyed object doesn't actually become null. so you'd be getting a different error if you were trying to operate on a destroyed object.

tired python
#
void OnCollisionEnter2D(Collision2D collision)
{
    if (collision.gameObject.tag == "UIDroplet")
    {
        Debug.Log("Muahaha");
        Destroy(gameObject);
    }
}```
`Kinematic GameObject`
#

i am getting the error in the highlighted portion

slender nymph
#

and what is the actual error you receive

tired python
#

NullReferenceException: Object reference not set to an instance of an object

slender nymph
#

also you don't need a coroutine to delay Destroy, it has a second paramter for the delay

tired python
slender nymph
#

but . . . why? if you know it isn't necessary and that the Destroy call already accounts for a delay, why would you create a coroutine for a delay?
anyway, the NRE is actually likely being caused by the fact that unity will reuse those Collision2D objects

wintry quarry
tired python
# wintry quarry Can you show us the actual full error message you are seeing in the console wind...
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.Collision2D.get_gameObject () (at <f1a2e4fe3e024bda9959a5de412d1a5e>:0)
ColliderCollisionCheckScript+<DestroyAfterTime>d__2.MoveNext () (at Assets/Scripts/Collision/ToothlessCollision/ToothlessCollision.cs:28)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <a25ed31d46d841d0bef9ea31576356a5>:0)
#

this is 28

wintry quarry
#

why don't you just pass the GameObject as the parameter

#

Collision2D isn't something you should hold onto for a long time

wintry quarry
#

likely that Collision2D has been returned the Unity's internal object pool and cleared

wintry quarry
# tired python elaborate

elaborate on the proposed solution?

Change to this:
StartCoroutine(DestroyAfterTime(col.gameObject));
and just fix up the DestroyAfterTime coroutine to operate on a GameObject param instead of a Collision2D

ivory bobcat
# tired python elaborate

Start the routine with the game objectcs StartCoroutine(whatever.gameObject);Image provided, so I did not bother copying exactly as is.

#

Where you'd change the definition of the ienumerator function to take a game object instead

slender nymph
tired python
wintry quarry
tired python
#

aight

#

oh, but its copy of the object

wintry quarry
#

we don't know the source code for the property getter so we can't tell exactly what the issue is but basically you can't assume that Collision2D object will be valid in 1.5 seconds. It;s only guaranteed to be valid right inside OnCollisionEnter2D

tired python
#

not the actual obj?

ivory bobcat
slender nymph
wintry quarry
tired python
#

ok

#

wait let me digest

#

something like this?

#

both of them are different pointers pointing to the same address?

slender nymph
#

yes. that's how reference types work

#

except they aren't really pointers because that's not a thing you work with in c# (with the exception of unsafe code)

tired python
#

if the gameobject = null it returns a nre?

wintry quarry
tired python
slender nymph
#

only in unsafe code, yes. references are similar but not quite the same thing

tired python
nimble apex
tired python
ivory bobcat
tired python
ivory bobcat
nimble apex
#

C# and C++ is very very different

ivory bobcat
#

Safety generally precedes performance. C++ would have you opt for smart pointers rather than raw pointers

nimble apex
tired python
#

i don't know nearly enough to even begin to comprehend why that is so, but aight

#

ok, now the nre is not appearing

lavish thorn
#

I think pointers are useful when you want to handle memory yourself, so with static vs dynamic behaviors

#

in C# I don't think it's a thing just cuz uhh, well I don't know, I only used pointers for school making weird memory sections

tired python
slender nymph
#

was the error you were just getting not enough of an example?

ivory bobcat
wintry quarry
#

your error, mainly

tired python
#

ya, it does not produce that error anymore

slender nymph
#

because you're passing the gameobject around now, not the Collision2D

#

the gameobject was not the problem, it was the Collision2D and whatever it is doing in the property getters

ivory bobcat
tired python
#

last question, is there an instance where i would want to use a static collider with a rigidbody2D attached to the same GameObject?

tired python
slender nymph
#

can you be more specific about what precisely you are referring to? because that's a pretty normal workflow (assuming by "static collider" you are referring to just a collider because colliders themselves are not static or dynamic)

slender nymph
#

this had absolutely nothing to do with destroying the object

tired python
slender nymph
#

you are getting your terminology backwards. it was a static rigidbody. the collider is always static because it is not what controls whether it is dynamic, that's the rigidbody.

tired python
#

oh sorry

slender nymph
#

and you almost never need to use a static rigidbody unless you need to create a compound collider (basically treat all child colliders as one big collider) for an object that should never be affected by physics or move

ivory bobcat
slender nymph
#

a static rigidbody probably also receives the collision/trigger messages that are sent to child colliders so could probably be useful to make sure those messages are received by a root object

#

although it does appear that all collider2ds in the scene that don't have an attached rigidbody are all considered attached to the same static rigidbody so if you end up needing to move specific colliders that aren't part of a dynamic or kinematic rigidbody then you should put a static rigidbody on them because it's faster to move that way

tired python
#

another thing, i have kind of gotten the hang of how to use the Scripting API, but i don't know what the manual is used for

slender nymph
#

as you can see from the manual link i provided, the manual is meant to give information about different concepts

hot wadi
#

Scripting API is coding-specific, Manual is all the other stuff

#

Some like Addressables are not included in Scripting, so u have to look into Manual

queen adder
#

Do you guys use ScriptableObjects over Singletons?

grand snow
sour fulcrum
#

I've sometimes used some singleton-esque scriptableobject stuff in order to reference my content collections accessible statically

swift crag
sturdy junco
#

Hello :,DD

#

can i ask

#

how to get the main camera back when accidentally deleted

gloomy heart
#

ctrl + z

hexed terrace
#

this is a code channel, that is not a code question.
just rmb -> add a camera -> set the tag as main camera

sturdy junco
#

oh sorry im just really new in unity TT

hexed terrace
#

It's ok to be new, but, being new to unity doesn't mean you're new to reading and understanding what channel names mean, or mean you can't read channel topics.

lyric igloo
lyric igloo
#

what blend tree is?

wild bloom
# lyric igloo what blend tree is?

Simply put, it's something that organizes animations in the Animator when there are a number of animations that are somewhat similar to each other, like running without a weapon, running without a weapon, and light running. You can organize them all in the blend tree. I recommend looking it up.

lyric igloo
#

ok i will do you think it will fix my problem?

swift crag
#

i don't see how a blend tree would help here

swift crag
#

so if it's flipping between "Jump" and "Attack", look at the transitions between those states

#

is it possible for both to be valid at the same time?

lyric igloo
#

no cuse for it to move for jump or run its need attack to be worng and for it to go to attack its need to be right

swift crag
#

show the conditions for the "Jump" -> "Attack" transition

lyric igloo
#

i did

swift crag
#

no, you showed the "Run" ->" Attack" transition

wild bloom
lyric igloo
lyric igloo
wild bloom
lyric igloo
wild bloom
swift crag
lyric igloo
swift crag
#

what are the conditions for the "Any State" -> "jump" transition?

lyric igloo
#

oh

swift crag
#

note that this transition does not care if you're attacking

#

these transitions are legal at the same time:

Any State -> jump
jump -> attack

lyric igloo
#

yess i fixed jumping

#

you fixed

wild bloom
lyric igloo
swift crag
#

Any State can be tricky to deal with, since it really does allow transitions from any state

mellow rampart
#

Hello, I'm a complete beginner with Unity. I'm trying to work on a project, but unfortunately, I'm stuck on shaders and materials. The problem isn't so much the code itself, but Unity's logic. If someone could come and help me in pm, I would be very grateful. (I don't think I'm that far from figuring it out.)

wintry quarry
mellow rampart
#

okay, thanks

vast comet
#

Hello, what's the best way to make switching between splinecontainers smooth? I asked ChatGPT, this is what I got.

    public IEnumerator SmoothSwitch(SplineContainer oldSc, SplineContainer newSc, bool front, float targetT)
    {
        Transform bogie = front ? frontBogie : rearBogie;
        float currentT = front ? t : rearT;

        Vector3 startPos = oldSc.EvaluatePosition(0, currentT);
        Vector3 startTan = oldSc.EvaluateTangent(0, currentT);

        // approximate distance along old spline to switch
        float switchDistance = Vector3.Distance(startPos, newSc.EvaluatePosition(0, targetT));
        float speed = Mathf.Max(0.01f, Mathf.Abs(tData.currentSpeed));

        float elapsed = 0f;
        float duration = switchDistance / speed;

        while (elapsed < duration)
        {
            elapsed += Time.deltaTime;
            float blend = Mathf.Clamp01(elapsed / duration);

            // pretend moving along old spline
            float simulatedT = Mathf.Lerp(currentT,1, blend);
            bogie.position = oldSc.EvaluatePosition(0, simulatedT);
            Vector3 tan = oldSc.EvaluateTangent(0, simulatedT);
            if (tan != Vector3.zero)
                bogie.right = tan;

            yield return null;
        }

        // snap to new spline
        bogie.position = newSc.EvaluatePosition(0, targetT);
        bogie.right = newSc.EvaluateTangent(0, targetT);

        if (front)
        {
            t = targetT;
            frontSc = newSc;
        }
        else
        {
            rearT = targetT;
            rearSc = newSc;
        }
    }```
it kinda works, but its not real smooth.
rocky whale
#

are the values of x and y in a Vector 2 object always -1,0 or 1 ?

naive pawn
#

no, what makes you think that

rocky canyon
#

float, float, float.. can be any float

naive pawn
#

some apis, or some contexts, might only give those values, but that's a rule of that api, not of Vector2 in general

#

Vector2 is just 2 floats

#

a 2d vector

rocky canyon
#

oh (2) yeap.. float float

rocky whale
naive pawn
#

that's a rule of the thing you're reading the Vector2 from, not of Vector2 itself

#

consider what would happen if your keyboard were analog or if that input were hooked up to a controller's joystick

rocky whale
#

oh like the triggers on controllers ?

naive pawn
#

sure, those are usually analog iirc

rocky whale
#

ahh ic

#

ty

naive pawn
#

for axis inputs, the result is often "normalized", in the range 0 to 1
when it's from digital hardware, you get 0 or 1 - no in between values, that's what digital means

-# footnote: there are 2 meanings for normalized, the other applies to entire structs - a normalized Vector2 has a magnitude of 1, etc

crisp quest
#

how can i access that web where i can type my code and send it here ?

rocky canyon
#

!code

radiant voidBOT
rocky canyon
#

use an external paste bin ^ or codeblocks if its short enough

crisp quest
#

thanks bud

wintry quarry
empty cairn
#

Is Time.DeltaTime in seconds?

night raptor
naive pawn
#

it also helps to think of deltatime in seconds per frame (or per step, per tick etc as you generalize it)

boreal scarab
#

how do i disable this

#

it annoys me a lot

swift crag
#

this is an annoying one

#

I've seen it when my objects go flying violently out of bounds

#

there's no stack trace because the error only shows up when Unity tries to figure out the position of something on the screen

#

you don't get to see the moment where it went wrong

rancid berry
#

hey does anyone have any solid courses for C# beginner because well im not a kid and when i tried the ones on the front page they didnt really make me feel like I was learning to use C# creativly for games. If someone could help that would be great!

solar hill
#

well if you need a begineer tutorial for c# then its not exactly going to anything flashy or even related to game development that much

#

you should probably get a basic understanding of the syntax and language before you start applying it in unity

naive pawn
#

there are beginner resources pinned in this channel

grand snow
#

one link is dead

rancid berry
#

yea idk it feels a lil confusing

#

lowkey might not even bother with coding since im not smart enough yk😅

solar hill
#

well if you want to make games you have to learn coding regardless of how smart you are

rancid berry
#

ik but i have a learning disorder so things overwhelm me quickly and i dont know where to start. its easy for you as a seasoned dev to say " oh just start" when i dont know where to put my time because i feel like it will take me 10+ years to understand the basics and by the time i have that then i wont even want to do what i wanted to do...

naive pawn
#

coding kinda does that regardless of any learning disorders

#

it's hard to a degree, but it looks way harder than it is

#

maybe thisll help

(in general) there's 3 major parts to programming:

  • Language - The syntax, structure, and paradigm of each language
  • Library - The interfaces and utilities that each environment or toolset provides
  • Logic - The algorithms to do work at runtime

Logic is almost completely transferrable between each language and environment, you just have to learn the specific Language and Library that you're using
Language is also shared quite a bit between languages

of course, learning 1 part at a time is easier than learning everything at once, which is why tools like scratch or code.org are popular as coding courses for beginners, especially kids, because it only focuses on the Logic aspect

solar hill
#

im still a beginner all things considered lol and im still learning myself

#

i also dont know why you would quote "oh just start" when neither I or anybody else here said that, we even showed you explicitly what to start with

#

Anyways coding at its fundamental level is about problem solving in bite sized chunks, there are thousands of free resources online where you can start doing this

#

if you have some previous experience coding then thats great, it means adapting to c# should be really fast, but if not you should start with something more lowkey and not unity

ancient rampart
#

how should I go about instantiating and assigning a bunch of different materials onto my prefab?

I have a setup to edit colours, where it uses sharedMaterial so it affects all of the prefabs gameObjects that use the material, but I can't do that if I want multiple instances of the prefab, otherwise it'll affect all of them.

so I'm looking for a solid solution to make it so each prefab has it's own set of materials that I'll be manipulating through code (that would affect all gameobjects using each specific material)

#

and I know I could just make a list of gameobjects for each material type and then iterate through them but that sounds super clunky and kind of overkill

timber tide
#

Usually that's the idea, yeah

ancient rampart
#

oh, alright lol

#

it sounded pretty hacky but if that's what the norm is then I guess I'll roll with it

timber tide
#

You can however lessen the iteration if say you want a single variable to modify all instances, meaning you do want to keep some shared parameters between instancing and you can usually do that with global shader parameters

ancient rampart
#

yeah I was hoping for a single variable to change the param in the shader, I just need it to affect all the gameobjects using that material, within the prefab

#

I was just gonna instantiate the materials, iterate through all gameobjects that I have in lists, assign the newly instantiated material, then edit that materials shader params the same way I initially did

#

it just seems very overengineered when it initially was just "edit sharedmaterial shader params"

timber tide
ancient rampart
#

hmm I'll look into those, thank you

swift crag
#

I wouldn't expect those to exist at runtime

#

much like prefabs

swift crag
#

I'm not sure what consequences that'd have in the editor, though

#

oh, wait, you're talking about making each instance of the prefab unique

ancient rampart
#

yeah

#

with a set of objects using the same instance of the material

swift crag
#

not making each prefab's material distinct from other prefabs' materials

ancient rampart
#

I can't edit the shader parameters if I did that though

#

otherwise it'd edit it for every prefab that uses those materials

swift crag
#

you should either:

  • access Renderer.materials and then mess with those materials (which will be made unique to the renderer)
  • use MaterialPropertyBlock to set specific properties on a specific renderer
ancient rampart
#

access Renderer.materials and then mess with those materials (which will be made unique to the renderer)

this would only edit a single gameobject that uses that material though, which is the main issue I'm running into

swift crag
#

ah, all uses of the material within a single prefab instance

ancient rampart
#

yeah

swift crag
#

that's the important part I missed

ancient rampart
#

like skin tone, hair colour, etc etc

#

since you can swap parts out, there are a bunch of seperated parts per prefab

fervent lagoon
#

Can i get some assistance with like super basic code? ive been trying to test out this line for like a week and ive went through a bunch of updates and dowloads and it looks like it would work but has two errors that idk how to fix

timber tide
#

i dont see any code

fervent lagoon
#

i didnt send it, i meant if i could vc with someone sometime about it

sour fulcrum
#

nope

frosty hound
#

You should open with your actual question/intention, instead of baiting a response.

#

We don't have VC in this server. Ask your question, show the code, and people can help if they can.

#

If it's "super basic" and a "line" , then there's no reason it needs to be a complex issue.

fervent lagoon
fervent lagoon
polar acorn
#

Given there's zero information to anyone to actually give a useful solution I figured I'd just give a solution without a question.

One of these days it's actually going to be a semicolon on line 14 and then I can retire

fervent lagoon
#

math

tulip relic
#

Why does my brand new Unity project have compiler errors from an invisible package

ivory bobcat
#

Other than that, they look like collab and version control configuration issues

tulip relic
# ivory bobcat Try restarting Unity

I tried restarting Unity, deleting and rebuilding a project, and clearing my cache. I ended up having to remove "com.unity.collab-proxy" from my manifest entirely and it worked

pliant lion
#

can i slice multiple images at once ?

charred monolith
hot wadi
#

We don’t recommend AI for beginners

left path
#

I'm not sure what is wrong with my player that is not moving

#

I have the new input system and I copied the tutorials source code :D

#

Okay nevermind

#

I think I should continue the another tutorial i'm doing

#

the main game

left path
#

But im not sure if these are okay

#

Looks fine

crisp quest
#

v += Physics.gravity * stepTime;//stepTime = 0.05f, v is vector 3
pos += v * stepTime;//stepTime = 0.05f, v = vector3, grenade pos = pos here

bro what does this means ? i cant understand why and how it is done and what its work
https://paste.mod.gg/eelrfqgkjytj/0 here

#

explain it please why it has done ?

sour fulcrum
#

where is the code from?

crisp quest
#

its a script of grenade throwing mechanism

#

it is showing the trajectory of the grenade

sour fulcrum
#

where is the code from?

crisp quest
#

AI

frail hawk
#

why dont you ask the AI then

crisp quest
#

GUys tell me how can i start using maths in my code ? how can i learn using formulas in my code

frail hawk
#

i think you should learn the c# basics first

#

it sounds like you are using ai code too much and you donÂŽt know what the code does

crisp quest
hot wadi
#

Seems like u are having trouble understanding the operators

crisp quest
hot wadi
earnest grail
#

!vscode

radiant voidBOT
dapper egret
#

Are scriptable objects a good way of doing eventa to keep everything modular?

proper apex
#

can anyone help me with a script?

grand snow
dapper egret
grand snow
#

Its not hard but you are moving the location of the event for little or no benefit

dapper egret
grand snow
#

then have the events not be static?

dapper egret
#

yes but then they will need a reference

grand snow
#

If the issue is getting a reference to the object then you just need to improve how you initialize and share dependencies

dapper egret
#

i want to decouple my scripts more

hot wadi
grand snow
#

anyway i cant comment more when I dont know specifics

hot wadi
dapper egret
grand snow
#

e.g. spawn player, init player with player data

dapper egret
#

ah

#

i see

grand snow
#

You dont have to only stick with Awake/Start...

#

DI frameworks exist for this reason, they essentially automate the initialisation of objects with dependencies

dapper egret
#

Hmmm never used dependancy injection before

grand snow
#

I would not recommend that just yet

dapper egret
#

ah ok

#

thx for the info

charred spoke
neon ivy
#

I'm working inside a namespace but I need access to an abstract class from outside of it in my normal project, how do I do that?

hot wadi
neon ivy
#

I can't no, it does restrict access

hot wadi
#

Show the abstract class

neon ivy
#

it's just there so this scriptable object can be added into a specific dictionary

hot wadi
#

What is the error it's showing?

neon ivy
#

I think I figured it out xD it's probably the assembly definition stuff, I don't fully understand it

#

nvm it's not working, I don't get namespaces Dx

hot wadi
neon ivy
#

it deals with the graph toolkit package which doesn't work nicely without assembly definitions

old skiff
#

u mean like this

#

like this?

neon ivy
#

I'm not sure I get your point

old skiff
#

u can access a class from a different script

neon ivy
#

I'm using a namespace and assembly definition

#

but I can't get the assembly definition to accept my class from outside of it

old skiff
#

oh

hot wadi
neon ivy
#

well it just doesn't know it's a class

old skiff
#

i could be wrong tho

neon ivy
#

yea it's my own class xD

#

it's in my assets folder

old skiff
#

import it

#

in your work

neon ivy
#

that is the issue yes, I don't think you understand the problem.

old skiff
#

i prob dont

#

atleast i tried

undone wave
#

the EventSystem object that gets created whenever I have UI elements has this property:

#

How do I access this through code?

#

which is no longer supported

keen dew
hot wadi
#

This could mean a numerous of things, but since u mention assembly, I have to ask

slender nymph
hot wadi
#

Yeah, I'm not familiar with this either so I did some experiment.
If the scripts are in different folders with their own .asmdef, u either have to include them in the same assembly folder, or create new assembly for each folder and reference them in each other.

neon ivy
slender nymph
#

Yes, as the docs say custom assemblies (like those created with assembly definitions) can't reference the predefined ones (like Assembly-CSharp)

neon ivy
#

I guess that did fix the errors so far, thanks for the info. the more you know I guess UnityChanThink

old skiff
#

is it just me or do some assets not show the material instead show a pink colour, if its just me how do i fix it

mystic crypt
#

quick question, i want to update my ‘line drawing’ code from instantiating circles while the mouse is held down (super intensive, looks like shit and i cant find a decent tutorial to interpolate it so theyre super spread out) into a line renderer or any other kind of line drawing substitute. however, ive got other pieces of code that check how many circles have been spawned inside of a hitbox to tell if youve ‘drawn’ inside of that hitbox for long enough and then run the rest of their code, would switching to a line renderer make this impossible (or at the very least alot harder) since im assuming itll all be treated as one hitbox and not many multiple ones?

frosty hound
#

If you want a straight port, you could technically use circles abstractly but instead of being actual circles with colliders they simply are the points that make up the line renderer.

As for tracking within an area, you can count the points inside of an area (there's probably papers online to determine if a point inside a shape). Or go the easy route and iterate through each point and do an overlapcircle call to check for collision on the hitbox and count them up.

mystic crypt
#

you may be underestimating how much of a beginner i am i hardly comprehend a thing you just said

#

but at least i know there are ways

frosty hound
#

Well, that's the extent I can go with mobile.