#💻┃code-beginner

1 messages · Page 807 of 1

sour fulcrum
#

I like my slop so i know who to blame 😇

slow blaze
#

This is moreso a question about vscode's workspace and how it handle new files
when I try creating a new file Project\Scripts\myScript.cs through vscode's file explorer, it does not get automatically added to the workspace or the Assembly-CSharp.csproj, and I have to manually modify and add that new file
Is there something I can do to make files get automically added?

teal viper
rancid tinsel
#

why is the 2nd line greyed out?

#

(Visual Studio 2026)

wintry quarry
#

It's probably recommending a collection initializer

rancid tinsel
#

so it doesn't throw an error or warning

wintry quarry
teal viper
#

Hover over the mixer group counts or the add method.

wintry quarry
#

e.g. MixerGroupCounts[soundEmitter.SoundData.mixerGroup = [soundEmitter];

rancid tinsel
rancid tinsel
#

maybe it's signalling that I can simplify this?

wintry quarry
#

yes that's my point

#

about the collection initialiazer

rancid tinsel
#

ah ok

wintry quarry
#

try hovering over different parts of the line

rancid tinsel
#

doesn't say anything

#

as in it just shows what the thing is like in the screenshot above

wintry quarry
#

Try Ctrl + . on the line

rancid tinsel
#

ah you're right

teal viper
rancid tinsel
#

and now I'm seeing the lightbulb - wasn't there before because I didn't click on the line

rancid tinsel
#

thanks guys!

low copper
#

I have a prefab called FloatingMenuIcon which has a has the following script attached to its primary object :
⁨⁨```
public class FloatingMenuIcon : MonoBehaviour
{
public Image image;
}

In another class I have a property:
⁨⁨```
        private FloatingMenuIcon iconOpen;
```⁩⁩
which I populate via :
⁨⁨```
iconOpen = Instantiate(iconPrefab, iconPanel.transform);
```⁩⁩
Can someone confirm. The actual way to make this prefab active/inactive is via:
⁨⁨```
iconOpen.gameObject.SetActive(false);
```⁩⁩
Just feels a little wierd and I want to make sure I'm not missing something. Thanks
radiant voidBOT
low copper
#

Hide the icon from the player

#

Or show it

#

The icon is a UI element

cosmic dagger
#

is that what you want to happen?

low copper
#

Yes, but I want to ensure I am doing it correctly

cosmic dagger
#

oh, so it doesn't actually de/activate when testing?

#

by the way, SetActive activates and deactivates the GameObject. it's different from just hiding or showing the ui element . . .

#

deactivating and activating a GameObject will stop all of its scripts from running Update and every component is disabled . . .

low copper
#

Everything seems to be working fine. I'm just suprised I am using .gameObject.....I'm new to all of this

cosmic dagger
#

.gameObject will access the GameObject the FloatingMenuIcon script is attached to . . .

wintry quarry
cosmic dagger
#

if you only want to show or hide the graphic, you can use a CanvasGroup component or disable the Image.enabled property (from the Image component) as well . . .

polar acorn
low copper
#

Ok. Makes sense. Thanks for explaining. I appreciate the help.

slow blaze
#
    void Interact()
    {
        RaycastHit hit;
        interactionRay.origin = mainCamera.transform.position;
        interactionRay.direction = transform.forward;
        float interactionDistance = 3f;
        if (Physics.Raycast(interactionRay, out hit, interactionDistance))
        {   
            if(hit.collider.gameObject.TryGetComponent<IInteractable>(out IInteractable interactable))
            {
                interactable.OnInteract();
            }
        }
    }```
I have a class Node : IInteractable and imlpements OnInteract();
Would this be a suitable to call the function (regardless of which class implements IInteractable)
The code does not function and I would like insight on why this fails to run (The function just Debug.Log("Interacted with" + this.name)
naive pawn
#

ok so sounds like 2 separate questions

#

the latter, debug to see where the flow of code reaches

rocky canyon
# slow blaze ```C# void Interact() { RaycastHit hit; interactionRay.o...

im using the same style system for my interactables..

  • IInteractable interface
  • Raycasts
  • and TryGet

debug like guy mentioned ^.. find out and make sure that each step of the code is running how it should. that will help u sniff out whats wrong.. i just had an incident where i culdnt get the Interact button press to work w/ the raycast but finally i found out I had it set to have to hold it .5 a second b4 the input system throws the event..

gizmo's help too.. but most likely the raycast is working as usual but something else is wrong.

#

ofc i cache my interactable the entire time im looking at it..
so then when i press interact i just call its .Interact() method from the cached

#

oh i meant to point out im using the ⁨TryGetComponent(out XXx xxx)⁩ signatur

naive pawn
rocky canyon
#

well, (minus this part) is wht i mean..

#

not sur what the specific terminolgy for it * is

naive pawn
#

it's the same signature, you're just letting it be inferred

rocky canyon
#

ahh oky ^

naive pawn
#

the explicit type parameter/generic?

rocky canyon
naive pawn
#

yeah they're type arguments

rocky canyon
#

<illtrytoremember>

foggy marten
#

How do I implement gyroscope/phone-tilting controls with the new input system?
I for some reason cannot understand how to actually get it to work:
What type of binding do I add in the Input Actions Editor? Why for some bindings I can choose Angular Velocity [Gyroscope], and for some not? How do I access the values later down in C# code?

#

I know this issue is easy to fix - but I'm to frustrated or tunnel-visioned to fix it by myself. Any help will be dearly appreciated.

foggy marten
naive pawn
#

How do I access the values later down in C# code?
i would assume the same way as how you use any other input

foggy marten
foggy marten
naive pawn
#

why would you assume so

foggy marten
naive pawn
#

Why for some bindings I can choose Angular Velocity [Gyroscope], and for some not?
probably to do with the type of the action

naive pawn
rancid tinsel
#

not code per se but is anyone else having extremely slow github clones today? normally it takes no longer than 3 seconds, but today its taking 10s of minutes

#

I thought it might be my AV or internet but I turned AV off, and internet is currently fine

naive pawn
#

i think it had issues like last night or something

#

says it doesn't have any right now though

rancid tinsel
#

weird

#

also it was super slow earlier for like 50% and then the rest it zoomed like normal in a second

naive pawn
#

may just be an isolated issue with some specific cluster or something like that

rancid tinsel
#

maybe, I just hope BitDefender didn't randomly break something without notifying me

arctic island
#

Starting game dev here. I want to create some games, but i'm unsure of what audience would be best. Can you tell me what types of games and on what plaform is most popular now?

solar hill
#

you should probably focus on learning first before thinking of optimal markets and genres

#

its a long road ahead

radiant voidBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

naive pawn
#

don't limit yourself to that kind of thing, just make what you want. otherwise you'll just burn out

arctic island
naive pawn
#

different gamers will like different things, all genres have an audience, it's not like there's going to be one genre that 80% of all "gamers" hyperfixate on

cosmic quail
solar hill
#

if youre trying to optimize your game for a certain audience youre sort of setting yourself up for failure in the long run

#

consider that the markets for popular genres are highly contested

#

if success is what drives you, youre better off doing something unique

naive pawn
#

a quick google seems to suggest the most popular genre has <20% market share

arctic island
naive pawn
#

that'll basically just have the same answer lol

#

plenty of people still play on pc though.

prime goblet
#

pc is quite popular because of steam, console is more expensive though for publishing

#

but if you don’t have any games what are ya gonna publish lol

#

additionally, you’ll likely want to make some kind of advertising or get your game out there so that no matter where you publish, people will actually know your game exists

#

you’ll find players on every platform for every genre, so it’s really your call

feral jacinth
#

what if something doesn't work and you have no idea how and why, are some tutorials are out dated?

solar hill
#

you can probably start by asking here.

naive pawn
#

are some tutorials are out dated?
yes, because time doesn't stop flowing

slender nymph
#

9 times out of 10 it's user error when it comes to code related stuff though

naive pawn
#

unless it's a tutorial from before 6.1 and you're on >6.1 and the error is the input setting

slender nymph
#

even that's still kind of user error since the error tells you what to do to fix it

naive pawn
#

yeah but technically the root cause isn't your fault

obsidian harness
#

i have a quick question and am wondering if someone could help me? i am trying to make a menu screen for a simple game i am trying to make but it doesnt seem to work

#

could someone help me it is my first game

slender nymph
#

!ask 👇 pay particular attention to the last few points

radiant voidBOT
# slender nymph !ask 👇 pay particular attention to the last few points

:thinking: Asking Questions

:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.

-# For more posting guidelines, go to #🌱┃start-here

obsidian harness
#

ow i am sorry yeah i looked it up on the internet but i saw some videos but i ceep stuck at the same problem: when i try to add the click event it doesnt show me the option to schoose the script i wrote for it

slender nymph
#

are you sure you changed the actual class name from NewMonoBehaviourScript?

obsidian harness
#

in the videos it shows the script at the botom of this list but for me it doesnt

#

yes i changed it into MainMenuManager

wintry quarry
wintry quarry
slender nymph
obsidian harness
#

this is what it is called is that right?

slender nymph
#

that's the file. the class definition is in the actual code

obsidian harness
#

ah so i need to change the name in the code?

slender nymph
#

yes, you already do see the component in the dropdown menu, you're just not recognizing the name because you've confused the file name for the component/class name

obsidian harness
#

ah ok i see thank you verry much

#

sorry it is my first time trying to build a game and thougt this woul be a good place to learn

slender nymph
#

i'd recommend learning the basics of c# outside the context of unity first. that will make learning unity easier because you'll already understand how the code is structured so you'll really just need to learn what the unity types do

cedar tartan
#

hi

naive pawn
cloud agate
#
    public void CreateNewProfileInMenu(Profile profile)
    {
        GameObject profileInstance = Instantiate(profilePrefab, contentParent);
        profileInstance.name = $"Profile_{profile.name}";
        Button button = profileInstance.GetComponent<Button>();
        TMP_Text[] texts = profileInstance.GetComponentsInChildren<TMP_Text>();
        texts[0].text = profile.name;
        texts[1].text = profile.CompletedLevelsCount.ToString() + "/4";
        texts[2].text = profile.GetOverallScore().ToString();
        button.onClick.AddListener(() => ProfileManager.ins.SetCurrentProfile(profile));
    }

    public void UpdateProfileList()
    {
        ClearProfiles();
        foreach (var profile in ProfileManager.ins.profileList.profile)
        {
            CreateNewProfileInMenu(profile);
        }
    }

    public void ClearProfiles()
    {
        foreach (Transform child in contentParent)
        {
            Destroy(child.gameObject);
        }
    }

Can someone explain to me why this causes a nullreferenceexception when used? (The UpdateProfileList/ClearProfile method)

#

If I add them regularly one by one with createnewprofileinmenu, it works fine, but if I destroy (reload the menu) it causes a nullreference exception on the first profile listener

ivory bobcat
#

You may want to provide the full error (preferably the entire console window) so we can validate the problem.

polar acorn
#

Which line is it?

cloud agate
#
NullReferenceException: Object reference not set to an instance of an object
ProfileMenuManager.CreateNewProfileInMenu (Profile profile) (at Assets/Scripts/MenuScene/ProfileMenuManager.cs:72)
ProfileMenuManager.UpdateProfileList () (at Assets/Scripts/MenuScene/ProfileMenuManager.cs:82)
ProfileMenuManager.ShowProfileMenu () (at Assets/Scripts/MenuScene/ProfileMenuManager.cs:42)
polar acorn
cloud agate
#

texts[1].text = profile.CompletedLevelsCount.ToString() + "/4";

polar acorn
#

texts, texts[1], profile, or profile.CompletedLevelsCount

#

One of those is null

#

Use logs or the debugger to find out which one

ivory bobcat
#

The idea is to understand the immediate problem (the source of the nre - likely some variable or collection) and then further figure out why it's null

cloud agate
#

ok, just thought it was the Button line because that's where it landed before. No idea why it lands here now

polar acorn
#

See what's null

#

then you can work on why's null

cloud agate
#

thank you eitherway

ivory bobcat
#

It isn't a difficult problem to solve so I hope you've successfully resolved the issue

cloud agate
#

I think I might have figured the issue

#

I made profile entries that might be wrong but are still on the json where I get them from

#

Yeah that's it

dreamy lance
#

does anyone know anything about creating custom navmesh agents ? or some other way of making ai pathing and stuff... im trying to make a car chase game and i need my ai to eherit the car physics and i dont think i can do that with the basic navmesh agent

#

im stuggling to find anything in google about it if someone has any recources that would be super apriciated

tender crane
#

!code

radiant voidBOT
tender crane
#

sorry that was for me

naive pawn
tender crane
#

gotcha, thanks

#

just asking if someone knows why this dictionary refuses to take in any values? i keep getting an "Argument Exception: Value does not fall within the expected range." for line 38, and any attempt to print the keys/values doesn't output anything. i've found similar issues online with delegates/dictionaries but couldn't find one exactly like this. the delegate signature matches the stored function signature exactly, i'm pretty sure.

public class Move {

    public int handCond;
    public delegate void MoveFunc();
    public MoveFunc moveFunc1;
    public MoveFunc moveFunc2;

    public Move(int handCond, MoveFunc moveFunc) {
        this.handCond = handCond;
        this.moveFunc1 = moveFunc;
    }

    public Move(int handCond, MoveFunc moveFunc1, MoveFunc moveFunc2) {
        this.handCond = handCond;
        this.moveFunc1 = moveFunc1;
        this.moveFunc2 = moveFunc2;
    }
}

public class punching : MonoBehaviour
{
    public Sprite palm;
    public static handScript RFist; // line 27
    public static handScript LFist; // line 28

    public float timer = -1f;  
    public string input = "";
    public Move move;
    public int buffer = 0;

    private Dictionary<string, Move> inputs = new Dictionary<string, Move>();

    void Start() {
        inputs.Add("J", new Move(1, LFist.Punch, LFist.Punch)); // line 38
        inputs.Add("L", new Move(2, RFist.Punch, RFist.Punch));
        inputs.Add("JL", new Move(3, LFist.ScrewPunch, RFist.ScrewPunch));
    }

...etc
tender crane
#

here is the code for the punch/screwpunch functions (stored in a different script)

public class handScript : MonoBehaviour
{
    public AudioSource audioSource;
    public Animator anim;
    public SpriteRenderer sprend;
    public playermovement player;
    Transform cameratf;
    public Sprite fist;
    public Sprite palm;
    public bool punched = false;
    public string move = "idle";
    float idlecool;

    public void ScrewPunch() {
        move = "screw";
        sprend.sprite = palm;
        Debug.Log("screw");
        anim.SetTrigger("screw");
        idlecool = 0.3f;      
    }

    public void Punch() {
        move = "punch";
        sprend.sprite = fist;
        anim.SetTrigger("punching"); 
        idlecool = 0.3f; 
    }

...etc
tender crane
polar acorn
tender crane
#

ArgumentException: Value does not fall within the expected range.
punching.Start () (at Assets/punching.cs:38)

polar acorn
tender crane
#

could be maybe? i dont know, line 38 and the two lines following it are the only lines where i add something to the dictionary, and they each have different keys ("J", "L", "JL")

grand snow
naive pawn
grand snow
#

haha great minds

polar acorn
#

It says it's in start, if the line they're saying is line 38 it'd be that line

naive pawn
#

but if it were coming from adding to the dictionary, the stacktrace would start from Dictionary.Add, no?

#

or was that line omitted?

tender crane
grand snow
#

Yea the stack would not ommit that im 99% sure

naive pawn
#

(i mean omitted by OP)

#

@tender crane could you show the first few lines of the stacktrace

wintry quarry
polar acorn
#

It could be on the LFist.Punch?

tender crane
naive pawn
tender crane
grand snow
#

Save all code changes, re play and copy paste the whole error text here

tender crane
#

this is what i see in console

grand snow
#

SEND THE TEXT

polar acorn
#

Where are LFist and RFist assigned?

naive pawn
#

....huh.

polar acorn
tender crane
# grand snow SEND THE TEXT

ArgumentException: Value does not fall within the expected range.
punching.Start () (at Assets/punching.cs:38)

grand snow
#

then somehow its the conversion to the delegate type?

naive pawn
#

do stacktraces not usually contain some internal unity code

wintry quarry
grand snow
#

Its normal to start from where unity first invoked it (from native)

polar acorn
tender crane
#

i just did the drag and drop thing once they showed up in inspector

grand snow
#

wait they are fuckin null

polar acorn
#

but where do you assign them

naive pawn
#

wth, does null.Method yield that instead of a NRE?

wintry quarry
#

hmmm possibly yeah

polar acorn
#

Where do you tell the code which handScripts the variables RFist and LFist hold?

wintry quarry
tender crane
#

DUDE

#

youre so right

grand snow
wintry quarry
#

that is definitely a weird error message

naive pawn
grand snow
#

TIL

wintry quarry
#

Probably the reference.Method delegates to some internal method which throws ArgumentException if the reference is null

#

that's super unintuitive

tender crane
tender crane
#

thank you all so much!!

naive pawn
#

if it were, eg, () => RFist.Punch() it'd be an NRE wouldn't it (but it'd only have the error once it was called)

grand snow
#

yay for member function wrappers

copper anvil
#

how the classes work in c# or unity idk?

naive pawn
#

you aren't going to get a different answer by crossposting here

polar acorn
fickle stump
#

A question how to approach my issue the correct/smart way:

I have an item interaciton script where I listen for if my item has dialog and if it has, I want to play the dialog first and when the dialog ends I want to activate my item. What's the best way to approach this? I don't think it's correct o change anything in my dialogue maanager right?

fickle stump
wintry quarry
#

is this running in Update or something?

#

!code

radiant voidBOT
wintry quarry
#

How do I tell the game/script to 'wait' here

But in general it sounds like what you want is a coroutine. Coroutines are designed to do exactly this

swift crag
#

notably, you cannot "pause" the Update function

#

this would freeze the game

fickle stump
#

I thought of something like a Coroutine, but as far as I've used it, it's mainly to pause something for x amount of seconds and not for 'wait until the dialog ended'

wintry quarry
#

Or WaitWhile

#

Or just yield return null in a loop and checking a condition manually

fickle stump
#

Interessting. This way I can make yield return !dialogue.playing basically

sour fulcrum
#

just mentioning cuz it trips people up sometimes

fickle stump
#

yeah I've been struggling with stuff like that unfortunately. Still learning stuff like that

#

very helpfull guys, thanks a bunch ❤️

wintry quarry
#

It's called a lambda if you want to look it up.

fickle stump
#

So, what I'd like to know now is, what do the brackets mean?

#

we basically give in nothing and then we wait until the state reaches its goal?

swift crag
#

() => 1 is a function that takes no arguments and returns 1

#

() => frame >= 10 is a function that takes no arguments and tells you if frame is at least 10

#

It captures the frame variable and retains a reference to it.

#

You could also write a method like this

#
bool PrincessRescued() {
  return frame >= 10;
}
#

and then do yield return new WaitUntil(PrincessRescued);

#

Unity will evaluate that function every frame until it returns true

#

anonymous functions are convenient for one-off functions that don't need a name

swift crag
#

we would say that it's a member of the class or struct

#

just as fields are

#

public int x = 123;

#

fields are member variables; methods are member functions

fickle stump
#

Woah that's a lot of infos

#

That's so interessting, but I feel like I'm not there yet to fully understand everything you said. But I'm sure I'll get there

swift crag
#

the important part here is that you're creating a function that tells you if you're done

#
public void Example() {
  System.Action<bool> isDone = () => frame >= 10;
  frame = 5;
  isDone(); // returns false
  frame = 15;
  isDone(); // returns true
}
fickle stump
#

As of now I understood the wait that I'm able to use coroutines and also can check if a variable changes its value
And thats a win in my books 😄

sour fulcrum
#

ya you dont need to know too much of all that just yet

fickle stump
swift crag
#

But if frame was going up by 1 in each Update loop, then yeah

fickle stump
#

oh yeah that totally makes sense

swift crag
#

Coroutines allow you to suspend a method and come back to it later

fickle stump
#

thanks for explaining 😄

swift crag
#

so you could be checking if a certain number of frames have gone by

obsidian harness
#

Hi i have a small question a made a game and now i want to ad a second level to my game. i did this by making a new scene adding a floor and copying the player from level 1 to level 2 but the movement doesnt seem to work even tho it has the same script. am i doing somthing wrong?

native widget
#

hello, how to get the rect information of the yellow on android keyboards?

naive pawn
#

define "doesn't work"

obsidian harness
#

so first of all when i hit the start button nothing seems to really heapen the screen doesnt pop up of the game starting, second is that when i hit the buttons to move the player doesnt move. and this all works in the first level. + in het debug nothing is showing that could be a problem to the movement

naive pawn
#

you have to do debugging to see where it's going wrong

elfin pike
#

I have issue planning. UnlockSystem( static class, which purpose is to save and load small data). It would be very demanding to always load from playerPref. What are options to save data.

ivory bobcat
#

Saving using json, binary etc

strange gate
#

For a 2d game is disabling game objects when out of view and enabling them when back in view sufficient enough for proper optimization if I have alot of game objects? (I am unsure on how much disabling Game Objects lightens pc workload)

naive pawn
#

quite an impossible question to answer

naive pawn
strange gate
#

Honestly just thinking about the future, currently my game isnt that far for me to have performance issues yet, but I will need to be able to be able to use it on old laptops as well. Also Id say at most around 100-200 game objects could be on the screen

naive pawn
#

that's quite small, relatively

#

unless you have a loop of 1000s of iterations in each gameobject, you probably won't have issues

#

don't optimize prematurely

#

you're just wasting your effort

#

if you have issues (or you suspect potential issues), figure out what is actually the culprit with a profiler, rather than just doing stuff and hope it's better

#

reactivating gameobjects does have a cost ie if you need to reawaken every rigidbody and add every collider back into the physics scene

strange gate
#

Okay thank you

astral meadow
#

Hi everyone, I have a question about hitboxes/colliders. Is there a way to generate a an accurate but performant colliders automatically ?
I'm currently adding capsule colliders for almost each limb

wintry quarry
quartz geyser
#

is making a game is just bunch of animation coded to run the game?????? lol

hexed terrace
#

no

quartz geyser
#

oh thats how i look at it

#

can someone know what it will take to make a game like gta san low quality and stuff like that?? like what pc/laptop will require to make it...

junior fossil
wintry quarry
#

Maybe 30 if you don't need high end graphics

quartz geyser
#

just need a laptop or pc

#

thats works faster

keen dew
#

GTA: SA was released in 2004 so anything newer than that

junior fossil
quartz geyser
quartz geyser
junior fossil
wintry quarry
astral meadow
wintry quarry
#

the actual gameplay systems are much harder

quartz geyser
#

i know will see what i can do for now

wintry quarry
quartz geyser
broken nest
#

What's the name of the function that returns the value between 0 to 360, adding or substracting 360 ?

#

I don't have the name of the operation so I can't find it on google

polar acorn
#

Modulo, %

midnight tree
#

Mathf.Clamp()?

broken nest
#

I actually coded it whatever

night raptor
elfin pike
naive pawn
night raptor
# elfin pike I think it's bad approach, if read JSON file multiple times. Better would be to ...

What do you mean by "multiple times" here? If you are going to read every frame, definitely bad. Is there a reason not to make a save & load system which reads the file once at start and holds the data in a class for the duration of the game or something similar? The file would be written to once when the player saves the game or leaves depending which you want. When the game is running, the save system (class or similar) is the way to get the data and modify it and from there the data can be saved later. Preferably the save system should keep track if anything has changed since overwriting a file when nothing has changed can be wasteful

earnest raven
#

Can anybody tell me why?

I'm trying to add cooldown and the general timer works, but the enemy throws the object no matter what the cool down is at.
the cool down can be at any number, and it will still throw it -- ignoring the check completely.

keen dew
#

Put Debug.Log("Cooldown timer: " + throwCooldownTimer); inside the brackets and see what it prints

wintry quarry
earnest raven
wintry quarry
#

Of course it's help

#

What did you try

#

Simply logging the values of all those variables in the if condition will tell you everything you need to know

earnest raven
#

I literally watched the cooldown in realtime as it was 5 and then went back up as if nothing happened

gaunt arrow
#

hi guys can someone help me with this. Im trying to get the 3d obj picked up, but it doesnt seem to work. Can someone help me pls im a beginner in this

wintry quarry
#

Use a debugger or logs

earnest raven
#

okay what's the difference from watching everything happen as it goes and debugging

#

I did use logs

radiant voidBOT
solar hill
#

please send your code correctly, nobody wants to download your .cs files in order to help you

wintry quarry
solar hill
#

also you have 2 more conditionals there, not just the timer, have you verified they are also being set correctly?

earnest raven
#

I put logs to check:
If THAT specific if() was happening (it was)
If the cooldown was above 0 when it happened (it was)

wintry quarry
earnest raven
#

Ikr. Let me set it up as it was

wintry quarry
#

You need to put a log inside the if and print the current value of each of those variables

earnest raven
#

i know

#

That's what I did

wintry quarry
#

well show us 😉

earnest raven
wintry quarry
#

theres no labels

earnest raven
#

no what

wintry quarry
#

Try this:

Debug.Log($"Entered the if statement. Timer is: {throwCooldownTimer}");```
#

and then run the game and show us what prints

earnest raven
#

what's the difference?

wintry quarry
#

it's just more informative. When you do Debug.Log(throwCooldownTimer); it's easy to mix that log up with another one since it's just a contextless number

earnest raven
#

It's the only Log printed I don't feel like there's any need

#
  • I've kept an eye on the timer in the inspector as well and even when it was above 0 it still threw the object
wintry quarry
#

It's very rare in my experience to only have one log printing in my code

earnest raven
#

It's the only thing I need right now as it's the only enemy

wintry quarry
#

regardless

#

can you run it

#

and tell us what it prints

#

or show us a screenshot of the console

wintry quarry
#

that's why logging or the debugger are the most reliable methods of debugging

earnest raven
#

I wasn't looking at the wrong variable??? it literally changed in real time

wintry quarry
#

Can you just run it and show us the console

#

this arguing isn't helping anyone

earnest raven
#

yeah jesus christ dude have patience

#

i didn't have Unity open

wintry quarry
#

I just guarantee you there's no way this is going to print a number larger than 0

naive pawn
solar hill
earnest raven
#

He waited for the cooldown once, but then it completely ignored the cooldown afterwards.

wintry quarry
#

So the timer is always below 0

naive pawn
#

it didn't change either

wintry quarry
#

Seems like you're not actually resetting it

earnest raven
#

I am

wintry quarry
#

So your variable here and whatever else you're looking at are not in sync

wintry quarry
#

!code

radiant voidBOT
naive pawn
wintry quarry
#

but the log confirms it's not a problem with this if statement

#

the problem is elsewhere

earnest raven
#

It plays the animation and an Animation event calls "ThrowCog" which should reset the cooldown near the end

wintry quarry
#

!code

radiant voidBOT
wintry quarry
#

these little snippets don't have enough context to know what's wrong

earnest raven
#

Why? this is the main focus

solar hill
#

why are you making it difficult to help you

wintry quarry
#

Do you want help or not? I'm telling you this isn't enough information. Why are you fighting us lol

#

There is no way for us to even confirm this code is running.

naive pawn
#

i feel like the value not changing between those 2 logs is a solid hint

#

but that hint is worthless without more context on where and how the value is being changed

wintry quarry
#

Yes it makes it very clear the value is not being reset

#

In fact that log printed 600 times

#

So there were 600 "throws" happening

naive pawn
#

for all we know you might be modifying throwCooldown instead shrugsinjapanese

wintry quarry
#

yeah we haven't even seen how the timer is implemented

elfin pike
naive pawn
#

keep a copy in memory to batch your saves, probably

#

no constant reading/writing to disk

wintry quarry
tender mirage
wintry quarry
#

caching is usually the word for an intermediate, faster form of storage between your application and the main storage system.

#

I'm just talking about the actual live version of the in-memory game data

tender mirage
#

Ah. So you’re refering to just modifying the variable that gets exported and not actually export it then.

wintry quarry
#

yes

#

and when we say "variable" here I'm talking about a class you specially constructed to hold your game data that needs to be saved

tender mirage
#

Still gotta learn what limitations constructors have compared to classes.

wintry quarry
#

they're not... comparable things

#

Unless you mean structs?

tender mirage
#

My bad. Yeah i was refering to structs.

And not the new instance with parameters

#

Constructors allow

naive pawn
#

...what?

#

classes and structs can both have constructors if that's what you're saying?

tender mirage
#

No. That wasn’t what this was about

#

Just a miss understanding on my part about mixing structs and constructors.

swift crag
#

the names do overlap :p

#

"struct" is short for "structure"

#

the name comes from C

tender mirage
#

Really? C had it?

naive pawn
#

yeah

swift crag
#

C#'s structs closely match the behavior of C structs

naive pawn
#

c++ also had classes (but the distinction isn't the same as c# struct vs class)

#

you could use either one as either a value or a ref/pointer type in c/c++

swift crag
#

if you have a struct-type variable, you are literally holding the struct's contents

#

rather than a class-type variable, where you're merely holding a reference to an object

swift crag
#

C++ requires you to allocate an object on the heap and then store a pointer to it to get behavior similar to C# classes

naive pawn
tender mirage
#

Wait. But c# doesn’t allow type references on structs, right? Also thanks for reminding me that structs are called structs and not constructs because i would’ve probably typed in construct next time that i used it

swift crag
naive pawn
#

what do you mean by "type references"

swift crag
#

Perhaps you're thinking of something else, yeah

tender mirage
#

Maybe i am. I should probably learn it.

swift crag
#

I wonder if you're thinking of this behavior

naive pawn
#

("type reference" isn't a term used in c#)

wintry quarry
#

if that's what you mean

#

a variable for a class is a reference to an instance of the class.

tender mirage
wintry quarry
#

A variable for a struct contains the actual data of the struct

naive pawn
#

given that boxing can be done on mutable types in c# unlike java or js

wintry quarry
#

Not really, no. You can't have two ifferent boxed references to the same struct

naive pawn
#

i'm referring to getting a boxed reference and then passing that around

wintry quarry
#

How would that look in practice?

naive pawn
#

yeah i'm just starting to work out the details in my head and it doesn't work lmao

swift crag
#

I mean, you can absolutely take a ref to a variable containing a struct

wintry quarry
#

yeah ref variables

swift crag
#

(the collision between "reference type" and "ref" is really annoying)

wintry quarry
#

anyway.... let's not complicate things haha

swift crag
#

ref struct time

#

💥

swift crag
swift crag
naive pawn
swift crag
naive pawn
#

yeah (that's a reference type)

swift crag
#

at one point I had read most of the C++ standard and could give an extremely pedantic answer about this

#

but i may have forgor

swift crag
#

classes get allocated on the heap and have to be cleaned up by the garbage collector

#

for example, Vector3 is a struct

naive pawn
#

conceptually,
class - some object or entity
struct - some bundle of data

tender mirage
#

If they’re a single instance. Doesn’t that mean you can just easily reference them from a another script?

naive pawn
#

you mean a singleton?

#

what do you mean by "they" in "if they're a single instance"

#

you're using a lot of vague pronouns

tender mirage
#

Well. You can have multiple structs. Can’t you just reference them all directly by name and get their variables?

wintry quarry
naive pawn
elfin pike
naive pawn
#
Vector3 a = new Vector3(1, 2, 3);
Debug.Log(a.x);
elfin pike
#

I made static class for storing and taking from storage file, but I have to keep taken data to use it until player doesn't needs it.

tender mirage
# wintry quarry Show a code example of what you mean
//Struct
public struct MyStruct 
{

    public int myStructVariable = 1;

}


//From a monobehavior script
public MyStruct myStruct;

private void Start()
{


    myStruct.myStructVariable = 1;

    //I was thinking of this but it doesn't work
    MyStruct.myStructVariable = 1;


}
swift crag
#

MyStruct is the actual type.

#

types are like a blueprint: they describe the shape of something

#

myStruct is a variable that contains a MyStruct

#

it's an object created from the blueprint

#

myStructVariable is a field – a variable that is a member of an object

#

you must have a specific instance of MyStruct to do anything with that field

naive pawn
wintry quarry
#

Yes

tender mirage
#

Yeah thanks for the clarification. I have had some exceptions to this rule where referencing the type was the way to go. I thought it was also the case with here

for instance having a public constant requires you to referencing the name of the class rather then a instance

wintry quarry
#

I think using a class is the better way to go by default you will run into fewer pitfalls

tender mirage
#

I see. Yeah i just use classes for now.

wintry quarry
#

You just need to remember to construct the instance with new()

naive pawn
#

anything else is

#

classes and structs arent' different in this regard at all

naive pawn
# wintry quarry How would that look in practice?

oh it does actually work

using System;

public class HelloWorld {
    public static void Main(string[] args) {
        I s = new S() { a = 0 };
        I t = s;
        t.a = 1;
        Console.WriteLine(s.a);
    }
}

interface I { int a { get; set; } }
struct S : I { public int a { get; set; } }
mossy belfry
#

Hello everyone!
I just developed a mini Android app and to release it on Google Play, I need a group of 12 testers for 14 days.
I already have 6 testers, so I’m looking for 6 more.
If you can help, please DM me. Thanks a lot! 🙏

swift crag
naive pawn
#

yeah

#

that's what i was referring to originally

#

i probably didn't articulate that very well

elfin pike
#

How to manage branching levels with requirements, max 20 levels. Should I make for each level id and store them in JSON, if unlocked? When levelmenu scene is loaded read file and enable each level point on map with same level id?

night raptor
elfin pike
night raptor
elfin pike
worldly mural
#

in simple words can someone please explain what [SerializeField] means?

polar acorn
worldly mural
worldly mural
#

does it just mean what you said after?

#

ah okay

night raptor
polar acorn
#

It lets it become a file on disk, which is how the inspector edits it

worldly mural
#

then whats the benefit of using serializefield? couldnt i just use a public float or public gameobject instead?

worldly mural
#

ah

#

okay, i understand now, thanks a lot!

night raptor
# worldly mural then whats the benefit of using serializefield? couldnt i just use a public floa...

You could make everything public but you shouldn't. Generally only the things that you need to access from outside the class itself should be public. The only, but noteworthy, real problem with things being public unnecessarily is how it can allow you to access things that are not meant to be accessed which can cause bugs in your code. [SerializeField] on private field is the better choice when you only want to make the field editeable from the inspector

mental finch
#

hey does anyone here have any tips or advice on starting c# coding in unity coming from 4 years of proffesional roblox scripting

solar hill
#

as for unity

#

!learn

radiant voidBOT
solar hill
#

👆 this is your best bet to get started

mental finch
#

cool alr

#

ok but if it asks for my credit card im swiping that shi down my ass cheeks

solar hill
#

tmi.

mental finch
#

yes but im tryna get started with scripting, i dont want to be copying things from tutorials because then im not learning

ivory bobcat
#

Unity learn should have some ultra basic scripting tutorials (using Unity) UnityChanThink

wintry quarry
visual junco
ivory bobcat
visual junco
#

Ok thanks

ivory bobcat
#

You should do the tutorial with a compatible unity version to not have to worry about Unity api integration.

grand snow
#

the api is so stable its fine
the only major thing is old input being depricated

red hull
#

Is there a way to turn on safe mode compilation without being in safe mode? This prevents race conditions from multiple agents while the other one can crash

grand snow
#

agents? huh?

#

safe mode is purely to let you fix compile errors before fully loading a project where assets could get mutated incorrectly

red hull
teal viper
#

What agents are you talking about and why would they "crash"?

red hull
teal viper
gaunt arrow
radiant voidBOT
red hull
teal viper
red hull
# teal viper Why would they crash? Or is it unity crashing? Anyways, having 3 different agent...

Its either an infite loop or crash with crashreport. Its as I said probably a race condition. you want to review what one agent did, while another one is still writing. While, as I said, a solution would be git worktrees, I noticed that the safemode doesnt seem to have that problem. I sometimes like to work on a single branch on a single module but different section of it in parallel to avoid git merges since they know this way more about each other. The job system that uses burst compile (which can be turned on to compile ahead of time in the editor.... I should uncheck it) is more fragile to it.
So thats why I asked the orignial question if I can have always save mode somehow.

Edit: Maybe its just burst compile, I have burstified everything gonna test so nvm

teal viper
#

I just asked what exactly crashes, because initially it sounded like the agents crash, and not unity.
I only expected an answer like "unity crashes". That's it. Nothing more, nothing less..

quick yew
#

Hello there. I made some changes on my laptop, but noticed this bug that makes the editor unusable, it wont ever load.
I downloaded the changesets on my PC and same thing happens. No idea what causes it, it was just script changes and this window pops up not during the play mode. Is there any fix to it or do I just have to revert the changesets? And maybe do something extra?

quick yew
#

I will look into it, thank you

ivory bobcat
#

How to properly post code:

#

!code

radiant voidBOT
teal viper
# gaunt arrow

You need to share a link to the paste site. Not screenshot it. It was specifically to address the screenshotting issue...

gaunt arrow
teal viper
#

You need to see how far the code executes.

#

Needless to mention, but you should of course make sure the component is present in the scene and is active/enabled.

fervent gull
#

nothing i'm doing can possibly make my in-runtime generated objects use a material other than default

#

i'm doing exactly what others are saying to do

#

all of them load as Universal Render Pipeline/Unlit regardless

#

my hexes are invisible when using this material and are fine using the 2D version so i'd like to switch

elfin pike
#

Can somebody explain, why are we using singleton instead of static class?

naive pawn
#

they're for different things

#

are you referring to some specific example?

#

we aren't psychic

sour fulcrum
#

instances are for when you want instances

in minecraft if theres a dungeon it might spawn 3 zombies

#

you'd want 3 instances of the zombie

#

most things in games you'd want instances

elfin pike
sour fulcrum
#

two big reasons that come up

  1. being able to mess with serialized/exposed fields in the editor (so it needs to be a component on a gameobject)
  2. need a monobehaviour if you want to run coroutines
#

a lot of my stuff in singleton setups ends up being static

wide wolf
#

Hi, sorry to bother you, but I have a question. I started using the Localization asset at the beginning of this week, but for the past two days, whenever I reopen the project, half of the things I had done in the Tables are not saved. Do you have any idea why? Just to clarify, I’m not in Play Mode while working and I save continuously.

ivory bobcat
#

If it's not, you should probably try moving the question to an appropriate channel or #💻┃unity-talk
Make sure to provide pictures and examples to illustrate what's happening and what is expected to happen.

wide wolf
# ivory bobcat Is this directly related to coding?

I think so, because I created a script that extracts the text inside the TMPs to then create the key, and I think it might be related — the only thing is that before I close the project, everything works fine…
If you think this isn’t related to coding anyway, I’ll move the chat right away, and thank you in advance.

median hatch
#
public void HookMovement()
    {
        if (isHooking)
        {
            Vector3 target = grapplingHook.hook.transform.position;
            // characterController.Move(distance * 40f * Time.deltaTime);
            transform.position = Vector3.MoveTowards(transform.position, target, 40f * Time.deltaTime);
        }
    }

does anyone know why my character is overshooting the target?

#

i want him to go exactly where the grappling.hook position is but he goes above it

ivory bobcat
#

You're teleporting btw by altering position with transform.

wintry quarry
ivory bobcat
wintry quarry
#

You're moving two different objects here it seems

median hatch
#

i got it working but thanks anyw!

charred monolith
#

a dbd fan game?

verbal dome
#

What makes you think that 🤔

solar hill
#

Dbd player learns about hooks

charred monolith
solar hill
#

Grappling hooks.

verbal dome
solar hill
#

Every zelda game since a link to the past

#

As well

charred monolith
solar hill
#

Its always what they litterally said they are doing...

#

Twice

charred monolith
solar hill
#

Nothing to apologize for, its just a bit of contextual misinterpretation

#

It happens

charred monolith
median hatch
#

this is the game

#

adding grappling hooks to it basically

charred monolith
tender mirage
#

Is there a way to convert a width or height of a rectTransform into worldspace distance? or perhaps directly get a ui elements dimensions in world space measurements?

tender mirage
#

I'll check that out right away.

rocky canyon
#

how hard/easy would it be to make a modular script that would take a mesh and add 3 bones to it..
making the middle bone be scaleable.. making a script i just add to objects like a stick of dynamite for example..

making it expand before it blows up... like in cartoons
really asking if its possible

#

i rigged this stick myself.. just curious if there was a code / time saving alternative

quick yew
#

Okay, again. This seems to be happening after alt-tabbing the editor. I reverted changesets to before it was happening but it still happens. It won't ever finish, I have to kill the process. Annoying as hell.

rocky canyon
#

what version of Unity?

quick yew
#

6.3 LTS (6000.3.2f1)

#

its native for this project

silk night
# rocky canyon

3 bones should be fairly trivial if its deterministic placement + distance based weighting, but that should also take about 30s per object in blender

quick yew
# quick yew its native for this project

I just realized im having 2 log errors in my console related to Unity AI (which im not using), could it be related to the editor freezing?

Error after 1 attempt(s): ApiNoLongerSupported -  -- Result type: PointsBalanceResult -- Url: https://generators.ai.unity.com -- Trace Id e6f736fd-c50d-4316-8eec-d7154addc265 => 

UnityEngine.Debug:Log (object)

Unity.AI.Toolkit.Accounts.Services.Core.AccountApi/<Request>d__16`1<AiEditorToolsSdk.Components.Organization.Responses.PointsBalanceResult>:MoveNext () (at ./Library/PackageCache/com.unity.ai.toolkit@5b5621a1dfc7/Modules/Accounts/Services/Core/AccountApi.cs:178)

System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<AiEditorToolsSdk.Components.Common.Responses.Wrappers.OperationResult`1<AiEditorToolsSdk.Components.Organization.Responses.PointsBalanceResult>>:SetResult (AiEditorToolsSdk.Components.Common.Responses.Wrappers.OperationResult`1<AiEditorToolsSdk.Components.Organization.Responses.PointsBalanceResult>)

AiEditorToolsSdk.Components.Organization.OrganizationComponent/<GetPointsBalance>d__4:MoveNext ()

System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<AiEditorToolsSdk.Components.Common.Responses.Wrappers.OperationResult`1<AiEditorToolsSdk.Components.Organization.Responses.PointsBalanceResult>>:SetResult (AiEditorToolsSdk.Components.Common.Responses.Wrappers.OperationResult`1<AiEditorToolsSdk.Components.Organization.Responses.PointsBalanceResult>)

AiEditorToolsSdk.Application.InternalServices.SdkOperation.SdkOperationService/<ExecuteRequest>d__4`1<AiEditorToolsSdk.Components.Organization.Responses.PointsBalanceResult>:MoveNext ()

System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<AiEditorToolsSdk.Components.Common.Responses.Wrappers.OperationResult`1<AiEditorToolsSdk.Components.Organization.Responses.PointsBalanceResult>>:SetResult (AiEditorToolsSdk.Components.Common.Responses.Wrappers.OperationResult`1<AiEditorToolsSdk.Components.Organization.Responses.PointsBalanceResult>)
silk night
pallid hound
#

Hi, I'm learning from scratch and following the tutorial I'm watching. Everything seems the same at first, but my controls aren't working correctly: W doesn't advance, A moves sideways, etc. I don't know what the problem is. If anyone could tell me, thank you very much.

silk night
quick yew
#

Which ones of these? I have to remove them in manifest since the editor freezes. All? Or is the last one the agent system?

    "com.unity.ai.assistant": "1.5.0-pre.1",
    "com.unity.ai.generators": "1.0.0-pre.20",
    "com.unity.ai.inference": "2.4.1",
    "com.unity.ai.navigation": "2.0.9",
silk night
#

!code

radiant voidBOT
silk night
quick yew
#

Yeah I think so too. Ill remove the first 3

silk night
pallid hound
#

I followed all the steps in the video and it's still not working.

silk night
rocky canyon
#

1 bone in the middle to scale.. and 2 bones on the outside for anchors or w/e ud call em

silk night
rocky canyon
#

awesome.. i code all my stuff into utility classes.. so i'll check it out and get the gist of it.. and rewrite something myself 👍

#

thanks for takin the time @silk night 🧡 🙏

naive pawn
#

-# man i'm so used to you being purple, i keep not recognizing you lmao

rocky canyon
#

-# the roles are irritating.. (i wanted just asset publisher bt it forced me to addanother)

silk night
rocky canyon
#

lol.. i'll start thanking robots when im forced to 😅

silk night
#

😄

#

I am pretty hesitant with AI stuff but usually let it generate stuff like this and make my own script out of it, just to get an idea how to start on stuff I have no idea about (like creating bones out of thin air)

dusty pendant
#

char cant rotate, why

naive pawn
naive pawn
radiant voidBOT
rocky canyon
random burrow
#

hello guys, Is there anyone that's bored enough to help me do a little 2d project in unity? I am new and don't know much but I have an assignment

radiant voidBOT
# naive pawn !ask

:thinking: Asking Questions

:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.

-# For more posting guidelines, go to #🌱┃start-here

rocky canyon
#

even if there were its unlikely

#

specifics here..

naive pawn
rocky canyon
#

go until u get stuck and then come back and get unstuck

#

rinse and repeat

naive pawn
#

no-one's gonna want to help without any info whatsoever lol

rocky canyon
#

booooring

random burrow
dusty pendant
#

I CANT SHARE CODE???

naive pawn
#

did you try to send it in my dms for some reason

dusty pendant
quick yew
#

Ah god dammit. I removed AI related packages from manifest, removed library folder, deleted packages-lock and AI packages are still in my project and I cant remove them. It breaks my entire projects in endless loadings.

dusty pendant
#
hello
dusty pendant
#
// normalise input direction
Vector3 inputDirection = new Vector3(_input.move.x, 0.0f, _input.move.y).normalized;

// note: Vector2's != operator uses approximation so is not floating point error prone, and is cheaper than magnitude
// if there is a move input rotate player when the player is moving
if (_input.move != Vector2.zero)
{
    _targetRotation = Mathf.Atan2(inputDirection.x, inputDirection.z) * Mathf.Rad2Deg + _mainCamera.transform.eulerAngles.y;
    float rotation = Mathf.SmoothDampAngle(transform.eulerAngles.y, _targetRotation, ref _rotationVelocity, RotationSmoothTime);

    // rotate to face input direction relative to camera position
    transform.rotation = Quaternion.Euler(0.0f, rotation, 0.0f);
}


Vector3 targetDirection = Quaternion.Euler(0.0f, _targetRotation, 0.0f) * Vector3.forward;

// move the player
_controller.Move(targetDirection.normalized * (_speed * Time.deltaTime) + new Vector3(0.0f, _verticalVelocity, 0.0f) * Time.deltaTime);
naive pawn
#

i didn't read particularly well in #🏃┃animation and i'm not super familiar with moving via animation; was the issue not related to animation config?

naive pawn
#

alright, do some debugging then - is the rotation code reached? what value you are setting?

#

also, you should not read back the value of transform.eulerAngles, you should track that value yourself

#

also, Atan2 takes (y, x), not (x, y)

visual junco
#

For learning to code would you guys recommend
1: Taking notes while listening
2: No notes just apply what you listen to with an editor
3: both
4: neither (something else)

#

it probably varies based on the person, but what do you guys recommend

swift crag
#

I try to avoid triginometry in general, haha

swift crag
#

Vector3 has some very useful methods

#

Quaternion, too

naive pawn
#

try them out and see what works for you

swift crag
#

Quaternion.AngleAxis(dir, Vector3.up); spits out a rotation that points in the direction of dir

naive pawn
#

oh that definitely would help yeah

swift crag
#

Vector3.SignedAngle tells you the angle between two vectors

#

(given a third vector to figure out whether it's a positive or negative rotation)

naive pawn
#

(though Atan2 in particular is a very conceptually simple operation imo)

swift crag
#

yeah, I just haven't had to use it in ages

dusty pendant
#

the euler thing isnt workin g

#

i want it to rotate to move direction only...

naive pawn
#

are the values for _targetRotation correct?

dusty pendant
#

ill see

naive pawn
#

well, are those the angles you expect?

dusty pendant
#

ye

#

man i started to hate unity

swift crag
#

I wonder if you're rotating the wrong object

dusty pendant
swift crag
#

This is going to rotate the object that the script is attached to

dusty pendant
#

its attached to player, aand i dont see any rotation

swift crag
#

Disable the script and manually rotate the player

#

(in Play mode -- not in Edit mode)

#

does the player rotate as expected?

#

Also, is there an Animator involved? If so, show me your hierarchy

#

(and even if there isn't, do that anyway)

#

I'm wondering if you are trying to rotate an object with a SkinnedMeshRenderer on it

swift crag
swift crag
#

Okay, that should be fine.

swift crag
#

When you're getting weird behavior, you want to start ruling things out

dusty pendant
swift crag
#

Okay, so something else is rotating the player

#

I don't think animators can affect their own object's position

dusty pendant
#

it was working fine before... all i did was remove jump functions and this bug came

swift crag
#

oh, they totally can

dusty pendant
#

i also removed jump functions

swift crag
#

hm, that doesn't sound like the cause

swift crag
#

Turn off the Animator as well.

#

really, just keep turning things off until you can rotate the player object properly

dusty pendant
#

ill try

swift crag
#

oh, okay, so you can freely rotate the player while the component is disabled?

dusty pendant
#

not game mode

#

when i enable it and try to rotate manually, it doesnt rotate

swift crag
#

by "enable it", do you mean going into play mode?

dusty pendant
#

no

#

enable script

#

it snaps asap

swift crag
#

i'm guessing the script has [ExecuteAlways] or [ExecuteInEditMode] at the top, then

dusty pendant
#

no

swift crag
#

and you are not in Play Mode?

dusty pendant
swift crag
#

okay, that's expected behavior

#

This means that no other script is trying to rotate the player

#

Make sure that you aren't setting the player's rotation anywhere else in the third person controller script

dusty pendant
#

no way

#

i disabled all transform.rotation and it still snaps lol

#

i have 2 transf rotation idk why that

swift crag
#

note that you could also be setting transform.forward

#

(or up/right)

#

if you can't find anything, share your whole script with one of these sites

dusty pendant
#

i enabled this and its useless

transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(inputDirection), RotationSmoothTime);
swift crag
#

!code

radiant voidBOT
worldly mural
naive pawn
#

does this object or the parent have an RB or CC?

worldly mural
naive pawn
#

you shouldn't be modifying its transform then - the rb will try to control the transform

#

use the rb to rotate

worldly mural
#

okay, ill try that out, thanks!

visual junco
#

for unity coding, would you pretty much only use float, int, string, bool, List<T>
or are things like double, decimal, char also sometimes needed

#

for variables

hexed terrace
#

yes, you use what's needed for the thing being done

frail hawk
#

it depends on what you need

swift crag
#

higher-precision data types (like double) should be used if your game requires the precision

blissful scarab
#

hey, mb dump question, but: how work Time.time? is it global time wich work with real world time or it count frames? Where i can use it? bc i think Time.deltaTime and courutine do all better then Time.time

small osprey
#

I know this ins't a code but there's a portuguese chat or server?
Is difficult for me communicate in inglish and i cant find one

solar hill
#

for unity specifically?

#

probably not

small osprey
#

Dang

#

I need start learn inglish xd

hexed terrace
#

English* for a start ;p

night raptor
# small osprey I need start learn inglish xd

Programming is a great way to learn English though since everything will be in English. My English was much worse than yours when I started learning Unity. Watching a lot of Unity videos and tutorials, reading discussions and documentations online and conversing in help servers like this one pretty much got me where I am now with my English skills. Don't be afraid to ask anything you need help with. Most here aren't native in English either, perfection isn't required to be understood. Good luck

pseudo barn
#

Hey, I'm currently learning to program on unity with zero knowledge
I already did some tutorial to understand how the app work and now I'm trying to do very small game project and asking chat gtp about how I could improve my code or how I could achieve something (I still try to think how I would do it personally so It doesn't feel like chat gtp is programing everything for me)
Tho it does make me wonder if there would be a better way to start my programing journey, does anybody have ideas or a good bot/ai made for programing that I could ask my basic question about ?

grand snow
pseudo barn
# grand snow Guess how we all learnt before llms came along a few years ago? There are plenty...

I did already knew about unity learn, and learn the super basic from there,
I was curious about starting another lesson about creating some basic games, but there is so much to look at those days that I didn't really knew what to pick and really wanted to do that one lil game I got in mind to train my self
If you think this would still be one of the best tutorials to follow I'll do it, was just exploring my option
Mb if that was a dumb question ^^;

grand snow
# pseudo barn I did already knew about unity learn, and learn the super basic from there, I wa...

Unity also offer a few game courses so either try those or some game tutorial series on youtube
https://learn.unity.com/course/3d-stealth-game-haunted-house

Unity Learn

Welcome to this revamped version of the beloved John Lemon game. We know how much this project means to many of you, so we made it even better! This time, John Lemon isn’t the only one sneaking through the shadows. Ivan von Vamp, a tiny vampire with a big personality, is also ready to embark on the adventure and escape the haunted mansion full...

pseudo barn
#

Alr thanks, I'll look them up, I appreciate the quick help ^^

wintry quarry
twilit jolt
#

hi everyone, quick question
i'm working on a basic dialogue system for my games lobby area, and it is fully working; but when i rotate the npc the direction of the text gets all messed up (first npc in the video is with 0 rotation, second one is rotated 180)

for context, i use individual gameobjects for each letter, so that i can have them scale up, and drop down
i spawn them in, inside a foreach loop that goes through all the char's of my dialogue string

GameObject temp = Instantiate(dialogueLetter, letterStartPos.position + (letterStartPos.right * (letterX * letterScale)) - new Vector3(0, lineDistance * letterY, 0), letterStartPos.rotation);

i use the right direction of the start position, as a reference, and the right direction points in the correct direction in the editor, if i check it with local editing, so i have no idea why it's moving the incorrect direction

would love some help cus i'm completely lost

rich adder
twilit jolt
rich adder
#

but if you rotate 180 it kinda makes sense its flipped cause your right of enemy may not be your right of cam

twilit jolt
# rich adder anything helps, where exactly does the startPos end up when you rotate npc, do y...

the start position is parented inside a worldspace canvas, that is under the camera, and the camera is under the root of the npc, so it's right direction shouldn't change (and when running the game and checking the scene view, the right direction is still pointing where it should be pointing)

i parent the letters under the startpos after they are done being set up, but that shouldn't change anything since by then they are already positioned (i also already tried positioning them after the SetParent, the result was the same)

also here is the full foreach that does the spawning (the ''star" is what i use as a new line marker, cus it's easier than doing multy char samplings for \n)

foreach(char c in dialogue.dialogueText){
    PlayAudioChar(dialogue.dialogueTextAudio[iter]);
    iter++;

    if(c == 'star'){
        letterX = 0;
        letterY++;
    }else{
        GameObject temp = Instantiate(dialogueLetter, (letterStartPos.position + (letterStartPos.right * (letterX * letterScale))) - new Vector3(0, lineDistance * letterY, 0), letterStartPos.rotation);
        temp.transform.SetParent(letterStartPos, false);
        lettersGen.Add(temp.GetComponent<DialogueLetter>().SetMeUp(c));
        
        letterX++;
        if(letterX >= lettersPerLine){
            letterX = 0;
            letterY++;
        }
    }

    yield return new WaitForSeconds(timeBetweenChars);
}

(ignore the star thingie, it broke the code display so i replaced the star char with the word)

twilit jolt
brisk edge
#

how are you setting letterStartPos? and does letterStartPos.rotation have the values you expect?

twilit jolt
rich adder
twilit jolt
#

okay, so i tried doing some tests to see if maybe i can find something, and it seems like the directions of the transform get fully inverted
i tried offsetting the letters using the .forward instead, and they move backwards not forwards (again, this only happens when i rotate the setup)

rich adder
#

are you changing letter scale anywhere?

bitter latch
#

How do I calculate the formula for the bullet trajectory?

#

And why do people have that formula?

twilit jolt
# rich adder are you changing letter scale anywhere?

i have a component for the letters, that animates their scale, and handles their drop animation, but that shouldn't really change anything, since i use a consistent transforms .right for the positions, that i never move, never rotate, and never change the scale of

oak remnant
#

Hello i have a question , when making a 2d platformer how do you manage having a character that is different in size, should all the sliced sprite boundaries be exactly the same, is it possible to do this?

rich adder
#

!code

radiant voidBOT
twilit jolt
#

i ended up doing a small workaround, so it works now tho i still have 0 clue why this even happened ;-;
thanks for trying to help out c:

mint imp
#

I cant find a proper place to start on makeing an "Atmosphere" shader.
Ive seen videos on the subject that are really advanced but i want to make a simple "Sky color fades out the further a point is from the center".
Then i can multiply it by the dot product of the suns position to only have it render on one side.

Picture is me mimicking what i want using transparent spheres, but anyone have thoughts on this?

naive pawn
mint imp
naive pawn
#

nah this is for scripting/c#

keen veldt
#

I want to ask a question about unity using all of my 32gb ram while on the frame debugger.
Where to ask?

median hatch
#

since everyone seems to be speaking the same way

#

this way you just activate the dialogue with the character data in it

#

there's no parenting, no need for everyone to have a dialogue prefab

#

and its clean

eager stratus
#

I'm trying to make a reference int field in a class so that the class can modify that int variable directly without caring where it came from. However, it seems C# isn't letting me do that telling me I have to upgrade to C# 11 or something (which I'm also told isn't supported by Unity). So how do I go about doing something like this?

#

It works just fine when it's a fresh ref int declared in the function, but naturally I want a class that can hold onto that reference. I just don't know how I'm supposed to go about doing that. Pointers maybe? But I'm a bit scared to use them since I'm told they're unsafe and the location of the data can't actually be guaranteed anyway

eternal needle
eager stratus
eternal needle
eager stratus
#

The idea is that it's a command in a JRPG and resource is supposed to be what ever stat is being used as a resource for the command. However, that resource could come from not just any character, but from a select range of stats. It could even come from an item stock. I don't want that distinction to matter, though. At the end of the day anything that should be fed here should be an int and its job is to deduct and/or add to that amount when it is asked to do so

eternal needle
#

what you're thinking of currently just sounds like a nightmare to debug, if it is even possible

eager stratus
# eternal needle you should probably make some interface or event instead then. Like if you store...

That would work if I wanted to just erase the distinction between a stat block and a consumable, but runs into another problem. A consumable only has one variable that can potentially be modified by the interface, but the stat block has like 3. The only solution I can think of to this is to put in a flag for the purpose of the statblock's implementation of the interface, but that flag is completely meaningless for the consumable's implementation

eternal needle
# eager stratus That would work if I wanted to just erase the distinction between a stat block a...

truthfully I don't see the point of anything related to the sample code above. This is basically asking how to externally modify values without a reference to the class
Like what purpose does this other class serve that it's being used to update a bunch of random numbers? There must be somewhere else that calls upon this other class to notify it to update. Move that logic to your consumables/stats instead

eager stratus
#

I just simplified a class to just this problem because I wanted a solution to this problem

#

I didn't want people asking what all the other variables did when it doesn't matter

eternal needle
#

maybe the solution here is really simple

eager stratus
eternal needle
#

a different way would just be to make a new wrapper class with the int you want, so you can pass that class around as a reference instead

#

which is essentially what you're trying to do with this ref int thing

eager stratus
#

I need it stored somewhere and C# is not letting me do that

eternal needle
#

ignore ref entirely here, it wouldnt be needed

eager stratus
#

And, as far as I've been able to test, if I just have a regular int as the field and assign it to the ref int it will simply copy the value. Any modification of that field will have no actual effect on the ref int that was passed in which defeats the whole point

#

I know I can do
ref int resource = ref inResource

But naturally then resource will only last as long as the initializer is running. I don't want that. I want it stored for later modification

eternal needle
eternal needle
#

i think technically a ref struct would immediately solve the one case you've shown, but Im like 90% confident you wouldn't be able to use it in the way you want
nvm I think this was only possible in later c# versions like you said above

#

it has limitations around how you can use it

sour fulcrum
#

You probably want this to be a whole class anyway later down the line incase you ever wanna do other stuff with it eg. perhaps associate front end stuff like text or ui or an event like i think bawsi suggested aswell(?)

ivory bobcat
sour fulcrum
#

when you could bake this into the value class itself

#

(ive done something like ScriptableStat esque stuff in the past)

eager stratus
# eternal needle it isn't needed in the slightest <https://dotnetfiddle.net/7IBTEB>

So you're saying that if I had a class

{
    public readonly Action<StatBlock, List<StatBlock>> action;
    protected TargetTag targetTag;
    event Action<ActionInfo> onCompletion;
    int resource;
    int cost;

    //I should see if the equal operator takes the reference of the variable, too
    public ActionInfo(string name, ref int inResource, int cost, Action<StatBlock, List<StatBlock>> action, TargetTag targetTag) : base(name)
    {
        this.action = action;
        this.targetTag = targetTag;
        this.resource = inResource;
        this.cost = cost;
    }

    public void DeductCost()
    {
        resource -= cost;
    }
}```

And tried to run this code outside of the class

```ActionInfo ultima = new ActionInfo("Ultima", ref cloud.currentMP, 80, SpellEffects.Ultima, TargetTag.Party);

ultima.DeductCost();

print(cloud.currentMP)```

That cloud.currentMP will be 80 less than it was before doing all of this? Or will it just be resource that is 80 less with cloud.currentMP being completely unaffected?
eternal needle
#

im not sure if you actually went through the code I sent above, i dont use ref anywhere

eager stratus
eternal needle
#

i sent you an example with exactly that. they are suggesting the same thing I wrote above

ivory bobcat
eternal needle
#

cause of the ref alone

eager stratus
#

It simply won't do anything because it's resource being modified and not currentMP

#

I want resource to work as a pointer to currentMP, but I'm not really sure if I even should be using pointers for this

sour fulcrum
#
class StatValue
{
  public int Value { get; private set; }
}
//eg. some thing that has a ref to whatever stat you want
private void ModifyStat(StatValue stat, int value)
{
  stat.Value += value;
}
#

similar to bawsi's just even more reduced

ivory bobcat
#

Well.. you're not assigning anything to inResource so it doesn't need to have the ref modifier

sour fulcrum
#

why wouldn't it

eager stratus
#

Oh wait I forgot to put ref

eternal needle
sour fulcrum
#

int's are not naturally reference based, classes are

#

so just have an int in a class

eternal needle
#

you do not need ref anywhere here

sour fulcrum
eager stratus
sour fulcrum
#

You'll probably naturally realise you can put a lot in that class

#

but in that example yes

ivory bobcat
eager stratus
#

I guess I can try it

eternal needle
#

🤦‍♂️ i dont think i can help if you aren't gonna actually go through the example which proves the entire thing you're asking about

#

if you were confused about the code sample i sent, then ask something. we shouldnt need 3 people to tell you the exact same thing

eager stratus
near atlas
#

How do I turn off the VS autocomplete?
It's trying a bit too hard to be smart and won't stop replacing my var with ShaderVariantCollection

teal viper
near atlas
#

actually it may be regular VS autocomplete and not AI
var wouldn't work anyway since I was in global
but I would've seen the red squiggle earlier if it didn't keep forcing the suggestion

hexed terrace
#

scroll up to the top, select 'var' .. I think it'll eventually stop suggesting that shadervar..

#

You don't want to turn intellisens off, you'll have to remember everything

near atlas
#

All I need from intellicode is the usage information you can find in the regular docs ngl

hexed terrace
#

I'd rather not have to keep going to the docs for spellings, or lists of available functions/ properties for things I already know but can't remember.. 🤷‍♂️

north kiln
#

Having to type code out completely would be a nightmare

near atlas
#

It's just comfier for me to not have something try to autocomplete what I'm tryna do

naive pawn
split mason
#

Hi guys hope you all are good and alright, so i was planning to practice my programming skills by creating different systems in unity so can you guys suggest me some systems like quest system etc etc that i should try developing from scratch which would help me be comfortable programming stuff that is entirely new for me!!

naive pawn
split mason
# naive pawn make something you want to make

i always wanted to make a robust quest system where i dont have to do some hard coded callings, should work in a way that i just import it in any of my game and i can use it, but the thing i suck at is how should i plan this all, should i just go with the hit and trial approach(i am trying not to use AI for starting, cuz that would eventually affect my judgement to solve problems)

naive pawn
#

start designing the system on paper (or in a diagramming tool or whatever you're comfortable with) before considering the implementation

solar hill
#

Take your concept, abstract it to its simplest form

#

Break that down into individual problems and go from there

near atlas
naive pawn
near atlas
#

ohh

#

I had it mixed up I think

naive pawn
#

intellisense is a normal feature that's generally very useful

near atlas
#

yeah I see now xp

tired python
#
void OnParticleTrigger()
    {
        Debug.Log("Particle Trigger Detected."); 
    }
naive pawn
#

that looks like a 3d collider, that wouldn't collide with 2d colliders

#

haven't we been over this

verbal dome
#

The green sphere is the particle collision shape/bounds

#

What is the question though? Like what is the screenshot supposed to show, the colliders are not visible

tired python
#

all my other colliders are in 2d 💀

#

my game in 2d

verbal dome
#

It is 2D. There's no 3D collider in that screenshot, Chris mistook the green sphere for a 3D collider

tired python
#

O_O

verbal dome
#

The whole point of the Triggers list being of type "Component" is that you can assign both Collider and Collider2D to it

naive pawn
#

i may have misinterpreted them though

tired python
verbal dome
#

But it's effectively 2D if you're using 2D triggers in the list

naive pawn
#

(well not a collider since it's not the same color, but i assumed it was using collider shapes under the hood)

verbal dome
#

anyone know why it On particle trigger gets called iff outside is set to callback?
🤔

tired python
#

check out the log and you will understand

#

i genuinly don't understand how people did unity before unity discord became a thing

verbal dome
#

So it is triggering the callback when you dont want?

tired python
#

it only triggers callback on outside

verbal dome
#

Seriously, don't assume that people understand what you mean just from a couple of videos with multiple things happening.
Prefer text explanations

verbal dome
tired python
# verbal dome And what do you expect?

i expect it to do that when enemy collider is inside the particle, but that's not the only problem. Even if I were to increase the radius of this trigger's radius scale field to a very high amount, it still triggers the callback even though the enemy collider should be inside this radius, and not outside of it

verbal dome
#

Why do you expect the "outside" callback to fire when it is inside?

tired python
#

if only outside has callback and everything else has ignore, callback should not happen when enemy collider is inside, entering, exiting this radius

tired python
#

i don't expect it to

verbal dome
#

i expect it to do that when enemy collider is inside the particle
Very contradictory but okay

sour fulcrum
#

Are you sure it’s the enemy triggering that? Those logs don’t confirm that

tired python
#

wait, let me explain what I want, and what i am seeing in one full elaborate explanation

naive pawn
#

-# this was expected of you from the start, man

verbal dome
#

The docs don't state if the particle needs to be inside/outside of all or any of the colliders

#

So that might be related

tired python
#

What I want:-

  • If enemy collider is outside particle, don't do anything.
  • If enemy collider entered particle or is inside particle, trigger OnParticleTrigger

To achieve this, I set Enter and 'Insideto Callback, and rest to Ignore
What I observed, nothing was triggered.

So I started tinkering with the various things and found out the following:-

  • Iff I set Outside to Callback, does any form of triggering ever happen, in any other scenario, where Outside has been set to Ignore, nothing gets triggered
tired python
verbal dome
#

Did you use OnTriggerStay/OnTriggerEnter or OnParticleTrigger?

#

Because the OnTrigger stuff isn't used by particle systems

tired python
#

changed it

verbal dome
#

Right, I see your edit

tired python
#
void OnParticleTrigger()
    {
        Debug.Log("Particle Trigger Detected."); 
    }
naive pawn
verbal dome
#

So it would have to be either of the Duck colliders

#

@tired python So when the Enter/Inside callback did not work, were the particles inside both of those colliders or no?

#

I'm not sure if it requires all or any

sour fulcrum
# tired python

am i dumb why are the game view and scene view different here

verbal dome
#

(In any case - I avoid using particle collisions for gameplay logic and treat them as purely visual components)

verbal dome
tired python
verbal dome
#

Well no, just some physics queries like raycast/overlapcircle etc.

#

Ofc it is harder than just enabling a checkbox in the particle system

#

But at least I know what's going on :p

#

Is your particle system at zero Z position?

tired python
#

the goddamn spline is set in the same xy plane, how the hell does z happen to change

#

z is changing everytime the duck moves

swift crag
#

Select the individual spline knots and make sure they have a Z position of zero

tired python
#

excuse me?

swift crag
#

If they're in Bezier mode, also make sure that both handles are at Z=0

verbal dome
#

I would expect Z to not matter in 2D but maybe there's some quirks with particle system since it uses both 2D and 3D collisions

swift crag
#

then click on the spline knots and make sure the handles are flat

#

(you may want to leave 2D mode to view this)

swift crag
verbal dome
#

When does 2D collision use Z?

naive pawn
verbal dome
#

Ah yeah that!

swift crag
#

That’s the erosion of the knot itself. I believe that does mean that the handles are sticking straight out on the XY plane, though

#

So that’s correct

tired python
swift crag
#

"Reverting back"?

tired python
# swift crag "Reverting back"?

i manually set it to 0, then i select another knot and then i select the same knot once again, and i see it have a value other than 0

#

like this

swift crag
#

hm, I'm not sure – the rotations might be getting affected by the neighboring knots

#

I'd start by getting the knots rotated correctly

#

notice how they're at a 90 degree angle to the 2D plane

swift crag
#

I think you can just give them a Y rotation of zero to flatten them out