#💻┃code-beginner

1 messages · Page 462 of 1

rich adder
#

maybe use a hashset and while loop

open gull
steel stirrup
#

Do you mean just a straight up (mostly) random number or is there a specific set you're trying to work from

#

because all you need for that is to create a System.Random object and call Next. Then just check against a hashset until you get a new one

indigo mirage
#

Hey all following brackeys Beginner tutorial, and im trying to add a function to my UI animation, however it keeps saying that it has no function name specified, even though it does

rich adder
#

one blank

indigo mirage
#

When I move it around in my Animation tab its the only one

rich adder
indigo mirage
#

yes, the little tab right below the 2 second mark, when I move it earlier theres nothing beneath

rich adder
#

oh alr, is this the only animation you have ?

indigo mirage
#

yes

open gull
rich adder
#

@open gull how many times are you taking numbers?

steel stirrup
#

queue or stack if you want to get fancy

#

fisher-yates if you want to get really fancy and/or care about performance

silk cave
#

so I was working on something and my unity program crashed and now I lost all my progress from the last hour and half =/

#

is there a way to get it back?

steep rose
#

depends, do you have version control and did you open unity yet after that?

rich adder
#

ctrl + s game weak

rich adder
steel stirrup
# open gull I didn't quite understand, sorry. I need to make sure that every time I press a ...

here's an example of what I mean ```private static System.Random rng = new System.Random();
static void Main(string[] args)
{
var set = new List<int>();
for (int i = 1; i < 11; i++)
set.Add(i);

        //shuffle
        RandomizeList(set);
        string str = "";
        foreach (var i in set)
            str += " " + i.ToString();

        Console.WriteLine(str);
    }

    static void RandomizeList(List<int> list)
    {
        for (int i = list.Count - 1; i > 0; i--)
        {
            var k = rng.Next(i + 1);
            (list[k], list[i]) = (list[i], list[k]);
        }
    }```
#

output is something like 8 6 2 7 10 3 5 4 1 9

rich adder
#
public int min = 0;
public int max = 11;
private HashSet<int> generatedNumbers = new HashSet<int>();
private int maxTries = 40000;
public int GenerateUniqueRandomNumber()
{
    if (generatedNumbers.Count >= (max - min))
    {
        Debug.Log("All unique numbers have been generated.");
        return -1;
    }
    int number;
    int i = 0;
    do
    {
        number = Random.Range(min, max);
        i++;
        Debug.Log("Count."+i);
    } while (generatedNumbers.Contains(number) && i < maxTries);

    generatedNumbers.Add(number);
    return number;
}```
prob more performant using a hashset
steel stirrup
#

I could be missing something but don't think so, this guarantees a unique value every time without a while loop

#

and no need to check

rich adder
#

bunch of lists > hashset
maybe if you used an array

steel stirrup
#

it's one list

open gull
steel stirrup
#
``` is just tuple deconstruction, it's still one list. Is that what was throwing you
rich adder
#

i misread the last method

#

no worries

open gull
#

Thanks, I finally understood how it works UnityChanThumbsUp

steel stirrup
silk cave
slender nymph
#

save periodically and set up some sort of version control if you haven't already so that not only are you saving the content, but also committing your changes so you can always revert and recover changes you've made

rich adder
#

yeah with the scene thats about it, all you can do is remember to save when you see the *

#

version control your project 100%

plain abyss
#

I would be very grateful if someone could guide me with the following
I have a TMPro Dropbox and options are in a random order in the inspector
is there a way i can have the options displayed in an alphabetical order in the game??

plain abyss
ember tangle
#

What have I done wrong with this Coroutine? Everything piece of this is tested and double checked but it wont trigger.

IEnumerator MeleeDistanceCheck()
{
    while (UnitsInMelee() < formation.unitWidth * 0.5f)
    {
        formationMovement.MeleeAdjustmentMovement();
        formationMovement.MeleeMove();
        yield return new WaitForSeconds(5f);
    }
}
#

the coroutine is started and stopped correctly, i've tested with multiple other conditions

#

and tested this condition in a debug line

slender nymph
#

keep in mind that if that condition is false then the coroutine will immediately end

ember tangle
#

So if UnitsInMelee() < formation.unitWidth * 0.5f is ever not true the coroutine automatically stops?

slender nymph
#

yes, why would it not stop? that loop simply does not happen if that condition is false which means it reaches the end of the method

ember tangle
#

I guess I am just going to do a timer

tardy plaza
#

!code

eternal falconBOT
tardy plaza
#
        void Equip4()
        {
            hotbar1.color = new Color(144, 95, 95, 183);
            hotbar2.color = Color.red;
            hotbar3.color = Color.red;
            hotbar4.color = Color.green;
            hotbar5.color = Color.red;
            hotbar6.color = Color.red;
            hotbar7.color = Color.red;
            hotbar8.color = Color.red;
            hand_9.color = Color.red;
        }
deft grail
tardy plaza
#

i know.

#

bro my messages keep saying blockedd by server

#

it wont let me explain

deft grail
ivory bobcat
#

You could probably just use an array and reference certain instances depending on your necessary configuration

tardy plaza
#

okay so hotbar1 is meant to be a darkred but when i run the game it is white, and i have no idea why

#

i ended up just doing color. red for the others because i coulndt figure it out, probably something stupidly simple that ive overlooked

#

i am right in thinking that it just takes the R G B and then opacity?

tardy plaza
eternal needle
#

between 0 and 1

tardy plaza
#

i tried this yeah, but when i attempt to use floats

#

it returns an error

deft grail
#

0.02f for example

#

and also theres something called Color32 so you can use 0-255

#

instead of 0-1

tardy plaza
eternal needle
tardy plaza
#

i did it said couldnt turn double into float, double confused me

#

and i forgot abt the f at the end

#

sorry for wasting your guys' time

#

thank you 🙏🏾

tardy plaza
deft grail
tardy plaza
#

😬

#

ive already finished the script and it works perfectly

deft grail
tardy plaza
#

i suppose, but also being the beginner that i am

#

i thought id save properly learning loops til another day

deft grail
tardy plaza
#

yep, and i am going to do so, today was all about working out ui for me

#

when i figure out loops yeah im gonna go back and refine it all

#

it definitely needs it

nova swift
#

Anyone got any tips on how to about recreating the smoothing effects of the rigidbody interpolation mode when it is set to interpolate? I have my player's rigidbody interpolation mode set to none as of right now as it appears to remove physics mishaps that happened when interpolate or extrapolate were on. But since that also removes the smooth movement, how could I go about getting it back while keeping the rigidbody's interpolation mode to none? I do have the player's sprite object seperate to the rigidbody object.

eternal needle
nova swift
# eternal needle you should say what those mishaps are, because you recreating the exact same sys...

The physics mishaps are a bit niche and specific. One of them is relates to the player going around a loop (pretty much the same way it happens in 2d sonic games) but sometimes losing speed on the exit. This happens when interpolate is on, but I believe it never happens with extrapolate or none. Extrapolate does bring out a handful of other issues though.

Either way, my thought process is that if changing the interpolation mode in the rigidbody appears to mess with the physics, then just smoothing out the sprite itself without changing how the rigidbody updates could be a possible fix.

eternal needle
teal viper
eternal needle
#

id say its more likely due to how you coded the rotation and such. Something is probably frame rate dependant

nova swift
nova swift
teal viper
#

Big code - more potential for bugs, so that's one.

nova swift
eternal needle
#

first place id look is if you are using the transform.position/rotation rather than rb. And if you are doing stuff in update rather than fixed update

nova swift
teal viper
#

That would just break the interpolation.

#

Make it ineffective basically

nova swift
teal viper
#

No. It just breaks the interpolation. Returning the jittering

#

To be honest, unity physics are probably not great at maintaining velocity in scenarios like these(as is real life physics as well ). You might need your controller to account for that.

nova swift
#

I probably should go into more detail about how I move the player. But I believe it's fully dependant on the rigidbody for moving around. The sprite on the other hand, moves to the player's position in the Update() via this line:

if (!isBeingCarried) sprite.transform.position = transform.position + transform.up * 0.25f; //Sprite position

This looks smooth and just fine when interpolate is on. But when interpolate is on, it seems to also create that one niche issue.
When interpolate is off, no issues appear to happen, but it does not look smooth, as expected.

nova swift
teal viper
teal viper
nova swift
# teal viper Not sure why you'd do that, but it shouldn't be a problem imho.

I move the sprite in that way because the player is in fact Sonic. When Sonic is curled into a ball and rolling around, his sprite does not rotate with his movement angle, and it has a rotation of 0. Since I relied on the rigidbody to move around loops and other curves, I have to later modify the sprite's vertical offset from Sonic to account for the slope angle, but anyhow that's unrelated.

nova swift
cyan wigeon
#

Question about unity Animator.
I currently run animations by doing animator.Play("animName")
this works fine so far but I want some smooth transition between various animations that happen through external events(what doesnt follow my code logic)
As well as something that would prevent specific animation from playing if another animation already is playing whats best way to handle it ?

void thicket
teal viper
cyan wigeon
#

I am looking at potentially having 20-40 animations so I would rather avoid anything that is hard to manage

nova swift
void thicket
teal viper
sand epoch
#

So I'm trying to find the position at the end of a ray that hasn't hit anything, a la my chart. How do i do this?

void thicket
eternal needle
nova swift
# teal viper Maybe share your code instead. Then we probably could identify this or any other...

Should I share just code that affects physics? The script in question is responsible for a lot things regarding the player (mostly just the physics though), which after some time I learned may not always be the best idea. It may so be quite messy to someone who isn't me, since it doesn't really make use of a finite state machine for a lot of code, since I ran into so many niche bugs using the rigidbody.

teal viper
#

!code

eternal falconBOT
fading mountain
#

Hey guys. Im having trouble in my game where I'm trying to spawn a collectable within a rectangle, but the player is inside the rectangle. if I just spawn it in randomly, without fail every single time, the collectable spawns in the middle of the rectangle. I can't just do a while loop that checks if the rectangle is a certain distance from the osition of the player and keep generating new random points until its far enough away because it is ALWAYS within 1 unit of the middle (and thus the player). This is what I've tried to do to fix this, but its still crashing unity because of an endless loop. I'm not sure what I can do. https://gdl.space/eruzasaqet.cpp

nova swift
#

There are also quite a few things in Update that do impact the physics, such as changing acceleration when standing on a certain surface, but even having moved those to FixedUpdate in the past temporarily, they never seemed to make any major differences to the physics.

teal viper
nova swift
#

As much as it may be a band aid solution, I think letting the rigidbody's interpolation mode be set to none is a valid option, since it appears to resolve any physics mishaps that were previously somewhat frame dependent.

eternal needle
sand epoch
#

@void thicket & @eternal needle this helped a lot thanks :))))(

teal viper
meager gust
#

yeah interpolation shouldn't be modifying the outcome of the simulation at all

nova swift
eternal needle
#

Not probable. It is literally part of the issue

nova swift
meager gust
nova swift
nova swift
plain garden
#

Hey rq

I'm trying to create a method inside of a class that positions an enemy. It says that Component.transform needs an outside reference?
Doesn't transform exist in the API?

transform.position = new Vector3(Random.Range(-10,10), Random.Range(-10,10), 0);

also btw the class is created outside of start and update

meager gust
eternal needle
teal viper
nova swift
meager gust
#

that would probably solve a lot of your determinism issues

#

just saying

nova swift
plain garden
# plain garden Hey rq I'm trying to create a method inside of a class that positions an enemy....

I have tried using Translate.position. using .translate instead, and checking the sutocorrect solutions. I also checked the Unity Scripting API and I don't know still

Also some other context that might be important:

It's in the class EnemyScript, the name of the script I;m editing
It's seperate from start and update. I tried adding in the code there and it didn't work
(This is C# btw)

    public class Enemy
    {
    void Spawn()
        {

            transform.position = new Vector3(Random.Range(-10,10), Random.Range(-10,10), 0);
        }
    }

Here's what the full block looks like
And again it says that transform component doesn't exist

nova swift
deft grail
#

does your class not inherit from MonoBehaviour 🤔

plain garden
plain garden
teal viper
deft grail
teal viper
deft grail
#

because thats what you WOULD need

plain garden
deft grail
#

the question is when should you NOT use it

#

each class default creates WITH MonoBehaviour

summer stump
plain garden
deft grail
summer stump
steel stirrup
#

You should never default to using monobehavior unless something absolutely needs to be physically in a scene and act directly on a base unity component like a Camera. Ex. you want to catch collisions or implement something like IPointer

#

The vast majority of your logic does not need to be and shouldn't be in monobehaviors

north kiln
agile summit
#

can anyone explain me difference in Lists vs Array? If they are the same thing, why are there 2 things... if a string is a string; there is no other datatype like string.

deft grail
steel stirrup
#

C# list is more akin to what would be considered a dynamic array in other languages

deft grail
#

if you make a list of 10, you can add 15.
if you make a array of 10, you can only add 10

agile summit
#

So we use array to limit our values quantity, and lists to add infinite quantity

slender nymph
#

the difference is that arrays are fixed size, and lists are resizable

#

in other words, if you make an array the only way to change its size is to allocate an entirely new array. for a list you can call Add and Remove to dynamically change its size at runtime (and even Clear to completely clear it)

agile summit
#

Haha, I was gonna write the same thing...

#

Oh I see... the List.Add Function is the main thing that makes List a List, We can't add values to Array at runtime, but Lists can do that

deft grail
steel stirrup
#

The other big benefit of list is access to Linq extensions

#

(this may also be a curse)

slender nymph
#

you can use those on arrays too, they are extensions for IEnumerable

steel stirrup
#

Are they? I was under the impression most went from icollection

#

Go figure

north kiln
#

Array implements that

outer coral
#

Linq ❤️

placid bay
#

i there a way to group multiple tiles on a tile map into one object, i want to rotate them together instead of separately.

obsidian granite
#

what's the difference between a streamingasset and a random file on my computer? i'm trying to make code that's meant for streamingassets work with a file anywhere on my pc.

wintry quarry
obsidian granite
#

yeah i have no clue why the creator said that it would only work for streamingassets, i piped in a path to just a file on my computer into it and it worked fine

#

ty praetor

velvet cape
#

i need help with me code, i just need a movement

sick storm
#

!code

eternal falconBOT
north kiln
eternal falconBOT
north kiln
#

After it's configured it'll be really easy to spot the issue and code properly in future with more confidence

sick storm
#

hi i am trying to make it so when i shoot a bullet left or right it knocks me back in the opposite direction the way the bullet is shot i think it is not working becuase some other code is overwriting it here is my whole script could someone help me https://gdl.space/yipogekixu.cs

#

im using addforce to do it and it works for up and down knockback but not horizontal knockback

mint remnant
#

body.AddForce(new Vector2(-knockbackForce, 0), ForceMode2D.Impulse);

#

that doesn't seem to take into account the direction of the bullet at all

sick storm
#

its not based on the bullet

#

it should just move the player in the opposite direction depending on if i am facing right or not and if f is pressed

mint remnant
#

opposite direction of what?

sick storm
#

the direction of the bullet

#

so if i shoot right my character goes left

mint remnant
#

but it doesn't include a direction in any calculation, just negative a variable

sick storm
#

do i need a direction

#

i did the same code for up and down

#

and it works fine

#

and how would i add a direction

#

body.AddForce(new Vector2(0, knockbackUp), ForceMode2D.Impulse); thats my code for upwards knockback and it works

#

body.AddForce(new Vector2(knockbackForce, 0), ForceMode2D.Impulse); this is the code for knockback to the right

mint remnant
#

you should include all that in a single calculation instead of picking a direction in if statements

sick storm
#

idk how to do that

#

and i have tried other instances of sending my character right and left and it doesn't work

#

i have a jump pad that works and when i went to make a boost pad out of the same code it did nothing (i changed the code to give a force on the x axis and it didn't work while the jump pad works fine)

#

i dont think it is a directional problem

#

and when i start the game and shoot immedient;y it works

#

only once

mint remnant
#

you seem to at least be trying, but you need a little work on design, it's a bit sloppy right now

sick storm
#

and right after i walljump the knockback also works

jolly temple
#

I write this code so my walk forward and walk backward can play when i press the D and A key

#
if(animator != null)
{
    if(Input.GetKeyDown(KeyCode.D))
    {
        animator.Play("Rifle Walk Forward");
    } 
    else if(Input.GetKeyDown(KeyCode.A))
    {
        animator.Play("Rifle Walk Backward");
    }
}
#

is it correct? Because when I tried to press the D key it doesn't play the animation

languid spire
slate haven
#

I am making a Third person game. So I want the player to look at the direction of where the mouse is going to. Also I want that player can look a little bit up and down on Y axis but not rotate around it. I set it up but my rotation looks very weird and it doesn't look at where mouse is

    {
      
        Ray ray = mainCam.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit))
        {
            
            Vector3 targetPoint = hit.point;

          
            Vector3 direction = targetPoint - player.position;

           
            direction.y = 0f;

           
            Quaternion targetRotation = Quaternion.LookRotation(direction);

          
            player.Rotation = Quaternion.Slerp(player.rotation, targetRotation, Time.deltaTime * 7f);
          
        }

    }```
wintry quarry
slate haven
plain abyss
chilly prism
#

how would I made it so when I go up to a plane and press 'e', I get a first person view of the cockpit, and I can pilot the plane?

willow scroll
chilly prism
#

ah

#

I'll find out what those mean, then give it a go

willow scroll
chilly prism
#

enum

#

and I also don't know how to do spherecasting

#

or input controls

willow scroll
#

Note that OrderByDescending, which orders the options by descending, exists

willow scroll
#
public enum State
{
    None,
    Person,
    Pilot
}
languid spire
#

@chilly prism Sounds like you need to !learn

willow scroll
#

You can name the constants however you want, and the previous message was not the best example

eternal falconBOT
#

:teacher: Unity Learn ↗

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

tiny rain
#

Hi guys, does anyone know how to assign an id to my prefabs at runtime? Didn't find any reliably way set the id in the prefab...
The only way I found is by spawning everything into the scene and referencing those, which could have some conflicts as any other reference to the prefab will remain unaffected, and besides that, it might have trouble if I ever search for anything in the scene...

willow scroll
chilly prism
#

understood

slate haven
#

I am making a Third person game. So I want the player to look at the direction of where the mouse is going to. Also I want that player can look a little bit up and down on Y axis but not rotate around it. I set it up but my rotation looks very weird and it doesn't look at where mouse is

    {
      
        Ray ray = mainCam.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit))
        {
            
            Vector3 targetPoint = hit.point;

          
            Vector3 direction = targetPoint - player.position;

           
            direction.y = 0f;

           
            Quaternion targetRotation = Quaternion.LookRotation(direction);

          
            player.rotation = Quaternion.Slerp(player.rotation, targetRotation, Time.deltaTime * 7f);
          
        }

    }```
willow scroll
languid spire
tiny rain
#

Now, previously I assigned the ids manually, but for reasons like better moddability, convenience, etc, I decided to go for a more automated approach

#

Which comes to this problem- I can't seem to set the id by script at all

slate haven
fossil tree
teal viper
tiny rain
#

Each prefab that can be saved&loaded have a monobehaviour called SaveableObject, originally there's an int field for the id

teal viper
tiny rain
#

Now I don't want to write the id manually anymore due to some annoying parts...

#

Especially since keeping track of order matters when I manually assign the ids

fossil tree
tiny rain
#

Now it's the Registry script, where on start it will Resource.LoadAll the prefabs and register them

teal viper
languid spire
tiny rain
#

But I'd very much prefer if the prefab knows it's own id too

teal viper
teal viper
fossil tree
teal viper
fossil tree
#

with a invisible circle return Physics2D.OverlapCircle(groundCheck.position, 0.02f, groundLayer);

teal viper
tiny rain
teal viper
fossil tree
willow scroll
teal viper
#

Instead of fetching from resources, assign the prefabs to an array in an SO or a manager manually. Then it's the same as what you already do.

#

And programmatically you can just do the same via code.

tiny rain
tiny rain
teal viper
teal viper
#

You might need to save the dirtied assets

#

So that the changes are actually saved to disk.

tiny rain
#

Also editorUtility would mean that it'd only work in the unity editor which uh... Might cause some trouble '^^

willow scroll
#

You have to simply keep track of the prefabs, when the scene is changed or the game is relaunched?

tiny rain
#

The id basically tells which prefab is to be loaded

willow scroll
tiny rain
willow scroll
tiny rain
willow scroll
#

Retrieve a prefab from AssetDatabase and assign its id

tiny rain
tiny rain
#

I figured that it sorta seems to work if the variable is serializable, and completely refuses to change when it's not

#

It makes it seem dangerously unpredictable

tiny rain
#

I've got a feeling that if I build it, it might not work just like when it's not serializable

eternal needle
#

if the variable isnt serializable, what are you expecting it to do at all?

tiny rain
#

And even if it does, who knows if it doesn't work on one or another platform

tiny rain
eternal needle
#

just like scriptable objects, you cannot use assets to save data like that. doesnt matter if its serializable or not

#

in a build it wont work at all

tiny rain
willow scroll
#

The prefab's variable can be changed, regardless of it being not serializable or private

#

It has to exist

tiny rain
#

I'm only trying to save it during one playthrough

tiny rain
#

I gotta go... Well, thanks for trying, though the issue is weird, trust me

#

You can try set up a small test and see for yourself

languid spire
# jolly temple Debug.Log?

Debug.Log is one of the very first statments you should ever have written in Unity. If you do not know what that is read the docs or !learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

eternal needle
willow scroll
#

And so, you can then simply save it to json?

tiny rain
willow scroll
eternal needle
tiny rain
#

The registry does provide a nameToId dictionary, but I thought that it's for the best to avoid accessing a dictionary whenever I need the id

#

I'm busy putting together all necessary code to show the registry's functionalities, it'd probably make things clear

eternal needle
tiny rain
eternal needle
#

nothing about that requires writing an ID at runtime. Just do it in editor

tiny rain
#

In a sandbox game

latent juniper
#

Hello! I'm making my first game (a side scroller) I made the player movement script now and I'm able to move horizontally. But my character is tilting and then falling on their side. Is it because of my capsule shape collider? How can I make them not fall?

tiny rain
#

In the editor, yep, definitely gonna go well

languid spire
latent juniper
#

collider I meant collider :"

tiny rain
#

And I did mention that I started off writing numeric ids manually, however... It causes quite some trouble '^^

eternal needle
#

nothing about it being a sandbox game changes what i said. This is too vague for me, im not playing 20 questions honestly.
You dont need to write them manually, write it via script and use SetDirty to save it

#

i do the exact same thing, this isnt some weird impossible problem. And yes it definitely goes well

languid spire
latent juniper
languid spire
#

So you are using Rigidbody, in which case my previous comment stands

tiny rain
#

Well... That means that it's strictly in the editor, while I'm hesitant about restricting it to this as I wish to keep some modability to it, while having numeric ids could very well make things clash...

latent juniper
tiny rain
#

But yes, if it's not for that, it could very well be compiled in the editor without trouble

eternal needle
#

modders know they have to jump through hoops a lot of the time

#

worry about getting your system actually working, no ones gonna be modding it if you dont actually publish it.

latent juniper
tiny rain
#

Ight... Well, since it looks like there's no clear answer to how I could assign ids the other way around, I guess that my choices are very limited now

#

Thank you guys, see ya

eternal needle
#

it looks like you were also given a few ways above by others on specifically how to assign a value at runtime. Im not sure what the problem really was, but you should show code if you're having coding troubles.

tiny rain
eternal needle
#

oh, for some reason that link isnt loading for me. Not sure why

#

ah it loaded

#

im also not sure what the actual issue is, like does this code not work? really this just looks unneccesary to me. Id just drag these into some list/array and then assign the values at editor time.
If you or a modder wants to add a new ID, drag a new prefab into the array. or alternatively create some editor script which does this for you and assign an ID at the same time

tiny rain
#

Either:
Abandon the idea of this more complicated registry and go a very simple way, ditching some possibilities that might become a pain to change later on, primarily anything like content that may or may not exist

Instantiate prefabs into the scene or something, all references must be by registryId or registryName, and never use findGameobject style stuff

Prefabs don't have id, any everytime you wish to find id of a prefab, you have to fetch nameToId[registryName]

tiny rain
eternal needle
tiny rain
#

What's your thought on the possiblity that it'd be a handicap later on tho?

#

Just curious since I'm always torn between choices thanks to that

#

A relatively performant, reasonably straightforward way, or a simple way that might have future troubles...

eternal needle
#

You could say the same about using unity. Why choose unity when it's possible it doesnt have a function you need? Might as well make your own game engine to ensure everything is there

tiny rain
#

And since the code isn't homongous or reach beyond a small circle, I consider it very much so straightforward

#

However the second line is... Well, I think that it's true, or maybe not, I just never know if I should be concerned

eternal needle
#

Be concerned when you actually run into an issue. I dont see how there would be any issues. Any manual work can be avoided with editor scripts

tiny rain
#

Well, it's only during startup, I've been suggested to purely use string ids too, and I've read some stuff comparing numeric versus string ids

#

String id is definitely a performance hit throughout the game, while the registry was a startup thing

upper nymph
#

Hey guys, I'm not really sure what the issue is here, please help

tiny rain
#

You're trying to use generics here, but the class has nothing to do with generic...

languid spire
#

you are missing the generic on your class declaration

tiny rain
#

I don't think that a monobehaviour can be generic in the first place tbh... Can it?

languid spire
#

of couurse it can

tiny rain
tiny rain
# languid spire of couurse it can

Eh, I'm not quite sure about that... How do you give a Monobehaviour a type like it's some generic? Really uncertain how the inspector will interpret it...

#

Behold! A Generic monobehavior!

#

Well, I'm being jokish there, sorry xD

upper nymph
#

ohhhh, sokay, mistake on my part XD

tiny rain
#

But really, it just got invalidated

eternal needle
languid spire
#

You are always giving a Monobehaviour a Type

class MyClass : MonoBehavious

is giving the Type MyClass to Monobehaviour
so

class MyClass : Singleton<MyClass>

does exactly the same thing

tiny rain
eternal needle
#

Thatd be a major surprise to everyone who already uses the same generic singleton implementation that is publicly available online

tiny rain
#

Eh... Well, fair point, although the second one made it... Not generic?

#

I mean, the baseclass is generic alright...

#

But during the inheritance there's nothing generic to it anymore

#

It's fixed to Singleton of a specific type

#

But yes, I overlooked that it could be inherited, sooo mistake on my part xD

languid spire
#

I must admit I find it a stupid pattern to use, I mean inheritance is for mutable parent classes and something that is immutable like the singleton pattern (also badly implemented in this case) is just a waste of space

tiny rain
#

Well... True, singletons are typically just a static variable of itself, and assigning itself to the static variable on awake, there's usually no reason to generalize them

#

I used it in my registries only cus it's pretty lengthy and repeatedly used

teal viper
uneven mulch
#

ok so i was jus doing some things on unity and all of a sudden no buttons work. none work

#

i dont have any code that does that

tiny rain
#

I think that that'd not even be a code question anymore... Right?

#

Oh, you mean in-game ui?

uneven mulch
tiny rain
#

Check the event system component

#

It might be using the wrong input system or not exist in the first place

#

Otherwise there might be a panel blocking it, maybe you added a transition screen or something?

uneven mulch
#

nope

tiny rain
#

Both are normal?

languid spire
#

did you delete the Event System?

tiny rain
#

I mean, you checked that you have an event system like this?

#

Might look different depending on which you're using

uneven mulch
#

i dont recall using an event system

#

maybe i couldve removed it

teal viper
#

If you removed it, then pointer events wouldn't work.

uneven mulch
#

yep that was it

#

i removed it by accident ig

fossil tree
#
using System.Collections;

public class CompleteCameraController : MonoBehaviour {

    public GameObject player;       


    private Vector3 offset;         

    // Initialisation
    void Start () 
    {
        offset = transform.position - player.transform.position;
    }
    
    void LateUpdate () 
    {
        transform.position = player.transform.position + offset;
    }
}```
why i have blue bar in my screen since i put the following camera
tiny rain
#

I'm not 100% sure if it's the case in the video, but I have a suspicion you're seeing the gap between sprites at times

tiny rain
#

Answer's above

warm rock
#

hey, when I have a public Text loseText
when i try to use loseText.enabled = true; it doesnt show it on screen, i resized and positioned it. . . i even clicked on the Check mark on top in the inspector

#

i have using UnityEngine.UI; ready too

fossil tree
willow scroll
warm rock
fossil tree
willow scroll
willow scroll
warm rock
willow scroll
willow scroll
#

GameObject.isActive(true) doesn't even exist

warm rock
#

it worked for me tho

willow scroll
#

Show the code

warm rock
#

wait

#

wrong code

#

it was setActive not isActive

willow scroll
#

You meant gameObject.active?

willow scroll
warm rock
#

ye thats what i wanted

willow scroll
#

Yes, that's a correct approach for assignment

warm rock
#

im just new and stupid so im confused and confusing

#

ty anyways

fossil tree
fossil tree
#

ty

neon mirage
#

Hi all! I'm trying to find the Restart game function, as stated in the Game Maker's tutorial. But I can't. What should I do?

languid spire
cunning flint
#

hey how can make the player more slow than this?

languid spire
#

you have not saved your code

neon mirage
#

Thank you!! Its working!

wintry quarry
cunning flint
cosmic dagger
wintry quarry
#

The calculation you're doing doesn't make much sense

cunning flint
wintry quarry
#

So the movement code is hard to decipher and hard to reason about

wintry quarry
cunning flint
wintry quarry
raven hill
#

quick question, I want to draw a ray for debugging, but I cant use + and I need it to be the length of a raycast. What else can I do?

#
Debug.DrawRay(transform.position, Vector3.down * playerHeight * 0.5f, Color.black);
#
Physics.Raycast(transform.position, Vector3.down, out slopeHit, playerHeight * 0.5f + 0.5f)
short hazel
raven hill
#

thx

short hazel
#

The issue with your current code is that, as operations are evaluated left-to-right (as you only have multiplications), Vector3.down * playerHeight is evaluated first, which produces a vector, which is then multiplied by 0.5f, which produces a vector, and you can't add a vector and a float.
When you reorder the operation by adding parentheses, it will add all the floats first, before multiplying it with the vector

neon mirage
#

Hi all, my bird don't fly upward when I click space?

#

ty❀

keen dew
#

Show the bird's inspector in Unity

neon mirage
keen dew
#

birdIsAlive is false

neon mirage
#

OOOOOOOOOOOOOOOOOOOOOOOOOO

#

Thank you!!!

umbral rock
#

!code

eternal falconBOT
umbral rock
#

hey, can someone help me with this code? https://hastebin.com/share/inubatovob.csharp
why is my cube rotating because of this? he moves on the Z but he rotates while moving..

short hazel
umbral rock
#

huh? what do u mean? its not my code but its because of the cube object physics?

short hazel
#

Yeah the physics engine interprets the friction between the cube and the ground and generates some torque
You can freeze the rotation from the Rigidbody's Inspector if you don't want that

umbral rock
#

aaah i see yess! thank u very much. i was so confused lol i thought i had created some sort of animation haha

obsidian granite
#

What should I do if I want to store important game files in an external folder? For example, save data. Where should I write it to? I want to make sure it's a place that will be there both before and after I build

#

Like save data, level data, etc

deft grail
#

you can use that

obsidian granite
#

oh sick ty

deft grail
languid spire
void thicket
#

persistentDataPath is fine

languid spire
#

persistentDataPath is not included in a build so would be unsuitable for level data

languid spire
obsidian granite
#

standalone

wintry quarry
languid spire
#

then streamingAssetsPath is OK, it is Read/Write on windows

void thicket
#

Are you meant to store level desingn data?

obsidian granite
#

well, more accurately i'm storing .jsons with information about levels

#

and some files to go along with it

void thicket
#

Is this user specific or something every user shares same value

obsidian granite
#

the player uploads two files and my code creates a json, then my code is going to zip them and save them. but i'm not sure where i should save the zipped file

obsidian granite
obsidian granite
void thicket
#

So just persistentDataPath?

#

That’s R/W, just the data is not with the game when you deploy

obsidian granite
obsidian granite
#

i just need the folder itself to be there when deployed

umbral rock
#

i know this code isnt working and cant ever work but why? can someone explain why it doesnt work? is it because the transform.localrotation = Quaternion.Eular(mouseX, mouseY, 0f) is always setting the rotation to the input of your mouse so if u move it it will set it to the input of your mouse and if u stop your mouse it sets it back to 0?

https://hastebin.com/share/ofobuludun.csharp

wintry quarry
#

So it makes no sense to use it in this way

obsidian granite
void thicket
#

Axis is delta
Looks like you want to accumulate the value

obsidian granite
#

transform.Rotate(mouseY, MouseX, 0);

crimson saffron
#

hey i was following this (https://www.youtube.com/watch?v=kXbQMhwj5Uc) youtube tutorial on how to implement a gun system in unity. i am a complete beginner, this is my first time trying to make a game, and i am at 6:24 but nothing is being output into the console. here is a screenshot of my code if you can find anything wrong with it.

I present to you my longest video yet. Sorry for all the mistakes in the video, I usually don't make such long videos.

In this video, I teach you how to create a simple weapon system. In future episodes, we'll add weapon switching, and visual/sound effects.

PROJECT LINK: https://github.com/Plai-Dev/weapon-system/

Like & Subscribe!

Timestamps...

▶ Play video
short hazel
ruby python
#

Looks to me like you're missing some code in 'Update'

#

Ohg nm, ignore what I just said.

crimson saffron
#

that is all the tutorial is telling me to do at the moment. visual studio is currently updating but once its done i can show you the code for playershoot (another c# script which is meant to call the shoot function(i think))

short hazel
#

Other code isn't necessary at the moment, debug first so you can pinpoint where the issue exactly is

crimson saffron
#

ok, i was just thinking that maybe the bug is in that script instead

#

but like i said this is my first time

ruby python
#

It could be as simple as things not having colliders for the raycast to interact with. Might be worth taking the Raycast line out of the if statements in the first instance to see if your raycast is actually working?

crimson saffron
#

im sorry if this comes across as a silly question but how would i do that?

short hazel
#

Too fast, take it step by step. Maybe none of the code is being executed right now, so no need to deploy the full debugging tools yet

crimson saffron
#

ok

#

i tested the shoot function and that seems to be being called correctly

short hazel
#

Okay, move the log further into the if statements until you don't get it anymore to see which one is failing

crimson saffron
#

found the issue, the gun had no ammo in it 😑

#

lol turns out it wasn't resetting when i stopped playtesting which i thought it did

short hazel
#

If it's data from a ScriptableObject, it most likely won't reset until you restart the Editor (in the Editor) or the game (built executable)

crimson saffron
#

yeah i fixed this by instead storing it as a variable and setting it to the magsize in the start function

ruby python
#

Hi all,

So, I have this little bit of code that populates a UI panel with 'starting' values

    public void PopulateResources()
    {
        foreach(AvailableComponents availableComponent in availableComponentList) {
            GameObject newAvailableComponentPrefab = Instantiate(availableItemPrefab, componentParentPanel.transform);
            Image resourceIcon = newAvailableComponentPrefab.transform.GetChild(0).GetComponent<Image>();
            Text resourceName = newAvailableComponentPrefab.transform.GetChild(1).GetComponent<Text>();
            Text resourceAmount = newAvailableComponentPrefab.transform.GetChild(2).GetComponent<Text>();
            resourceName.text = availableComponent.componentDataContainer.componentName;
            resourceAmount.text = availableComponent.componentAmount.ToString();
        }
    }

Because I need to access and change some of this data and display in the UI (specifically the resourceAmount), I was wondering if it would be best to add each GameObject that I'm instantiating to a list and then referencing the list later to get the various 'bits' of the prefab? Or would there be a better way?

languid spire
#

Add a script to the prefab which contains all the references and Instantiate that script, you can then pass that around if you need to

ruby python
#

Forgive the potential stupidity, but how would I then reference a specific prefab that I've spawned and change it's values from an 'UpdateResourceCount' method? Sorry, drawing a blank. lol.

languid spire
#

when you spawn the script using the Instantiate method it returns a reference to the instantiated version of the script, i.e. the one on the instantiated prefab

vital gale
#

is there a way to disable / enable new InputSystem's callbacks in a condition? (I need to disable 2 callbacks (one regarding to move and one regarding to camera movement), when the player hits the escape button (a pause menu should show itself)) The reason is, when the player hits the escape and pause menu shows, the user can still move with the camera and the player body

ruby python
#

I'm so sorry, I'm still not really following.

For example, if I were to use a list my UpdateResourceCount() method would be something like....(simplified and missing things out but you get the idea)

UpdateResourceCount(int resourceIndex, int resourceAmountAdjustmentAmount) {

//Update the componentAmount value here
instantiatedPrefabList(resourceIndex).componentAmount + resourceAmountAdjustmentAmount;

//Then do the UI Update stuff
}

I'm not sure how to do the same thing just referencing the script on the specific prefab that needs updating (if that makes any sense?)

languid spire
tender wharf
#

gamers, whats the best way to prevent this from happening when using a sphere collider for collision

#

essentially i can climb stuff that u realistically shouldnt climb

ruby python
tender wharf
#

idk if wheel colliders are good for arcade physics

languid spire
frosty wren
#

Is there a way to programmatically decrease shadow quality in URP? I have baked shadows using bakery and use mixed for my character and enemies.

I want to add a graphics settings allowing to have both realtime and baked on, only baked (disable all realtime) and another option to disable all shadows (realtime and baked)

ruby python
# languid spire no where near enough context for this to make sense. btw your original foreach d...

Okay, here is the full code.

https://hastebin.com/share/agoqomovih.csharp

In simple terms it's essentially an inventory system (space station construction/management game)

The player will be able to 'craft' components (that will then be used to build Modules onto the station), so I'm working on populating/updating the component inventory amount.

#

Screenshot for reference.

#

And just to be extra annoying. Another screenshot showing my 'AvailableComponentList'

languid spire
#
Create a new script MyScript like
public class MyScript : MonoBewhaviour {
public Image resourceIcon;
public Text resourceName;
public Text resourceAmount
}
add it to availableItemPrefab and fill the references in the inspector. Change the type of availableItemPrefab to MyScript
then your code becomes

MyScript newAvailableComponentPrefab = Instantiate(availableItemPrefab, componentParentPanel.transform);
            newAvailableComponentPrefab.resourceName.text = availableComponent.componentDataContainer.componentName;
            newAvailableComponentPrefab.resourceAmount.text = availableComponent.componentAmount.ToString();
#

@ruby python

tender wharf
#

uh, for some reason a scene works perfectly fine in editor while when builded it looks like this

#

would anyone know why this might be happening xd

languid spire
#

As we don't know what it looks like in the editor how can we tell the difference?

tender wharf
#

thats how it looks in the editor

ruby python
frosty hound
# tender wharf

Not a coding question. #💻┃unity-talk

If you're using multiple scenes, make sure you've actually added them to the build settings. Otherwise, make a development build and see if there are errors being thrown.

languid spire
ruby python
#

Riiight okay. Yeah, that was my original question about using a list. Sorry, I don't think I explained it very well. Thank you sparing the time though. Very much appreciated 🙂

rocky canyon
#

i take back what i said about it being quick and simple.. took way too much trial and error

steep rose
rocky canyon
#

exactly.. it woulda been way easier to point 1 object..

steep rose
#

yeah i used to do that in garrys mod lmao

rocky canyon
#

but once u start breaking it in pieces and having to recombine

#

it got challenging

#

check out the thread for the failed results lol

#

im gonna try to add predictive aiming soon.. (ive already realized i can't add it to the turret) the math is too hardcoded.

#

soo imma have the projectile *project where it will actually be in X amount of seconds) or w/e

#

and get the distance from the turret.. and then the turret will track that object instead

topaz ice
#
    {
        Debug.Log("Starting animation");
        TextBubble.transform.localScale = new Vector3(1.3f, 0.7f, 1f);
        yield return new WaitForSeconds(0.25f);
        TextBubble.transform.localScale = new Vector3(0.9f, 1.3f, 1f);
        yield return new WaitForSeconds(0.25f);
        TextBubble.transform.localScale = new Vector3(1f, 1f, 1f);
        Debug.Log("Finished animation");
    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "TalkingCollider");
        {
            if (other.gameObject.name == "1");
            {
                GiveMeASecond();
            }
        }
    }```

The last line (`GiveMeASecond();`) that actually is suppost to do something literally does... nothing.

Why?
languid spire
#

That is not how you start a coroutine

topaz ice
#

Well how DO I start it?

topaz ice
#

alr

steep rose
#

always look at docs

languid spire
#

you obviously did not read the docs you were linked to. StartCoroutine

topaz ice
#

so uh

#

I'mma get to reading

steep rose
#

you should

#

probably do that

languid spire
#

thats why there are docs, you you can find out and learn

summer stump
#

Looking up unity IEnumerator would lead you to coroutines

cunning narwhal
#

Anyone know why a demo project (QuizU) isnt loading the whole solution *in visual studio when I doubleclick on a script in the asset browser and is just loading the individual file? Other projects I have arent behaving this way

obsidian granite
#

how accurate is fixedupdate at running on a constant interval? i'm doing some stuff with MIDIs, and i have a midi being played. I'm using fixed update to constantly move forward a character based on how much time has passed in the MIDI. however, it's pretty inconsistent, with anywhere from 8-16 ticks passing each fixed update. the song's tempo isn't changing, so if it truly is fixed, wouldn't it be the same amount passed each update?

summer stump
languid spire
#

Unity is single threaded so FixedUpdate can only be as accurate as the deltatime of the intervening frames allows it to be

summer stump
#

@weak cedar Do not take a video of your screen with your phone

steep rose
#

i know you have that picture on speeddail

#

dont do it to him

weak cedar
weak cedar
lethal bolt
#

Is this the rigth way to do this because im not getting any logs?

summer stump
# weak cedar "move" is on update

It is trying to get outside the collider I guess
I don't think Move respects physics as much as other methods, but first try setting collision to continuous in the inspector

obsidian granite
summer stump
obsidian granite
#

and the colliders are set up properly

mint remnant
lethal bolt
obsidian granite
# mint remnant check collision.collider

they said they're not getting any logs, including the ones outside of the if statement. therefore, it's not an issue with parameters, nor can they check parameters

summer stump
#

The Three Commandments of OnCollisionEnter:

  1. Thou Shalt have a 3D Collider on each object
  2. Thou Shalt not tick isTrigger on either of them
  3. Thou Shalt have a 3D Rigidbody on at least one of them

(Stolen from digiholic)

obsidian granite
cunning narwhal
weak cedar
summer stump
#

Do you WANT it to penetrate?

obsidian granite
summer stump
#

Or do you want it to just not spin if it can't

weak cedar
summer stump
obsidian granite
vital gale
#

any ideas why this is not showing in the inspector?

weak cedar
obsidian granite
#

oh you are using rb.move, mb

languid spire
obsidian granite
#

thought it was transform.translate

summer stump
# weak cedar I thought rb move would do so

Velocity or addforce will do better but you also want physics materials. And you need to decide which of the three options will happen. Penetrate, prevent movement, or bounce back

weak cedar
obsidian granite
summer stump
weak cedar
#

I really don't understand

#

what do you mean

summer stump
languid spire
summer stump
#

Go inside the cube? Not rotate at all? Or bounce back?

vital gale
weak cedar
#

oh I see what you mean wait let me disable the rotation method

obsidian granite
#

if it's not serializable, it won't serialize

obsidian granite
weak cedar
vital gale
#

the PlayerInputActions is a generated class from the new input system

obsidian granite
#

did you write it? i'm looking through the new input system docs and i can't find that class

summer stump
summer stump
summer stump
#

Is it... happening in this video?

obsidian granite
#

when the cube is moving, it's 2.01 something, when it's let go, it snaps to 2

weak cedar
summer stump
#

So the .01 movement is really... an issue?

weak cedar
#

hurts my eyes, so yes

summer stump
#

Ok, well that is just a normal thing that happens with physics 🤷‍♂️

#

I have 0 ideas how to deal with it except redoing your own physics with raycasting or other spatial queries

You can try velocity or addforce as mentioned above

weak cedar
weak cedar
summer stump
cosmic dagger
queen adder
#

yo, i need to learn how to code.... tutorials on youtube dont help at all!

rocky canyon
#

!learn well dont use YT then

eternal falconBOT
#

:teacher: Unity Learn ↗

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

summer stump
#

Youtube is terrible for starting imo

rocky canyon
#

ya, youtube is more for niche tutorials/systems

queen adder
#

so what are yalll makin?

ashen umbra
#

greetings brothers , i am new to unity and wanna enhance my experience by game developing but theres one tiny problem .. I dont know how to code at all , is there any way that theres a built in code help thing in unity to atleast help in basic functions ?

rocky canyon
#

fps fallout clone

queen adder
#

im makin vr tf2

eternal falconBOT
rocky canyon
#

ohh.. neet lol

cosmic dagger
#

I don't make stuff; I break stuff . . .

rocky canyon
#

you'll still end up needing to learn how code flows

queen adder
languid spire
rocky canyon
#

ohh am i? i dont stay updated with visual scripting lol

ashen umbra
#

ill look for everything u guys said , Thank u very much !

languid spire
cosmic dagger
rocky canyon
#

but its still called BOLT right?

languid spire
#

no, it's called Visual Scripting

queen adder
#

why yall saying BOLT in all caps?

rocky canyon
#

makes it sexier

queen adder
#

oh aight

rocky canyon
#

but turns out bolt has been bought by unity.. so its just alled Visual Scripting

#

lame

#

i knew they bought it.. didnt know they rebranded it

cosmic dagger
rocky canyon
#

⚡ BOLT

queen adder
ashen umbra
#

btw for a starter like me , is 2d or 3d a good option ? i know 2d is simple and 3d bit complex but wanna know from experienced ppl

summer stump
rocky canyon
#

aka bolt

queen adder
#

i love making maps in 3d unity

rocky canyon
#

wanna make me a couple? 😈

weak cedar
queen adder
ashen umbra
#

Gotcha , thank u both .. ill go and collect some great free assests and try experimenting

rocky canyon
queen adder
#

oh aight

rocky canyon
#

soo far soo good

queen adder
#

yo i feel bad for whoever had to make the "sons of the forest" map

ashen umbra
queen adder
#

ik it was a team but its so detailed

rocky canyon
rich adder
queen adder
#

not judgin ofc

rocky canyon
#

lol, i was just lookin over a list.. can't say ive played any of em

cedar crest
#

Hi! I want to fix 2D camera width to 12 units on screen, and wrote this code:

// cameraWidth = 4000 (random number)
var currentWidth = camera.pixelWidth;
camera.orthographicSize = cameraWidth / currentWidth;

Which worked in the editor, but when I built it, it was not 12 units.
How do I do it properly?

cosmic dagger
ashen umbra
#

what is the short cut key to take screenshot on laptop ?

winter tinsel
rocky canyon
queen adder
#

heres a plot twist, i AM spawn camp games!!!!

ashen umbra
rocky canyon
queen adder
ashen umbra
rocky canyon
#

most likely i'll sue ur parents.. since ur probably not tax payer age yet

rocky canyon
queen adder
rocky canyon
#

win + shift + s allows u to snip only the parts of hte csreen u want..

queen adder
#

aight ima stop

rocky canyon
#

and then u can just paste it..

#

b/c it saves it to the clipboard

ashen umbra
#

Ah , thanks alot .. i really appreciate ur help

half forum
#

Hello every one, does any body knows why when i use this code.
print(Input.GetAxisRaw("Horizontal"));
I always get -1 when Game window is selected but when is unselected it returns 0?
Im using a keyboard for input

queen adder
#

im bored

rocky canyon
#

ur not getting any inputs

#

so therfor (0)

#

if ur getting -1.. that means ur S key or ur Arrow Down key is stuck 🤪

queen adder
#

magic

rocky canyon
#

use Debug.Log over print also

#

print is the base-model.. no one wants that

queen adder
languid spire
queen adder
#

tf did i do bruh

languid spire
#

Firstly I ain't your bro, Secondly look at your last few posts

half forum
queen adder
#

it aint hurtin anyone

rocky canyon
teal viper
# queen adder im bored

This is not a place for you to satisfy your boredom. Go to some social server that has an off topic channel.

languid spire
#

This is not a social server, there is NO off topic allowed

rocky canyon
half forum
#

Nope

rocky canyon
#

share your code..

half forum
#

This is everything 😵‍💫 🤣

queen adder
#

ill go

rocky canyon
#

must be some key thats getting inputs when it shouldnt 🤔

languid spire
half forum
rocky canyon
#

so its more likely ur A key or Left Arrow key

#

debug "Vertical" too while ur at it and see if its zero or -1

steep rose
rocky canyon
#

ya, lol.. had a brain fart

steep rose
#

ah

#

i just saw what you said

#

mb

rocky canyon
#

most times i seen this happen it was because someone had a gamepad plugged in with stick drift..

#

never seen it w/ no gamepad was plugged in.

rocky canyon
#

very interesting..

#

i havent a clue mate

#

try restarting unity?

steep rose
half forum
#

okay sadok

strong wren
#

@queen adder This isn't the server for random crap. Keep messages relevant.

steep rose
#

if you do it sounds like the controller is drifting to the bottom left

rocky canyon
#

BIG drift too

#

u could debug Input.Axis w/o the Raw part

#

and it'd give u a more accurate representation

steep rose
#

as long as the dead zones of the controller are small

rocky canyon
#

for Raw? i'd think it had to be over halfway to the edge

steep rose
#

i could be wrong

half forum
steep rose
languid spire
#

Mouse could be fucked/ Maybe?

steep rose
#

im not sure mouse affects Horizontal or Vertical

languid spire
#

Laptop+TouchPad?

languid spire
steep rose
steep rose
languid spire
steep rose
#

ahhhhhh

#

alright

#

mb 😅

languid spire
#

It is extremely odd though

ashen umbra
#

Guys , whats this for ?

rocky canyon
#

organization

indigo mirage
#

Hey all whats the correct string for left control, this doesnt work

rocky canyon
#

Keycode.LeftControl i think nvm thats KeyCode

ashen umbra
#

should i take it ?

indigo mirage
#

ohh, is left ctrl not a button

rocky canyon
#

not sure what the string is for button

languid spire
rocky canyon
indigo mirage
#

Ah ok i gotcha,

#

hmm its not seeming to detect when they key is down

half forum
# languid spire Mouse could be fucked/ Maybe?

Humm tried without Mouse and still having that error

I tried with this code and it is going well, so keyboard is okay
`float horizontal = 0;
if (Input.GetKey(KeyCode.A)) horizontal = -1;
if (Input.GetKey(KeyCode.D)) horizontal = 1;

print(horizontal);`

indigo mirage
rocky canyon
#

i cant remember if u have to have the new-input system enabled to view it tho

indigo mirage
#

i dont even have the analysis in my winow tab so

rocky canyon
#

ya its probably b/c i have the new input system installed

#

and my project set to use both of them

#

you have to have analysis in the window tab..

#

b/c how else would u run the profiler?

indigo mirage
#

yeah i do it wasnt in alphabetical, thats my fault, but it doesnt have the input debugger

rocky canyon
#

ahh okay

rocky canyon
#

the -1 must be coming from somewhere

indigo mirage
#

So i fixed it by just getting rid of the down, now its just input.GetKey

rocky canyon
#

GetKeyDown = the frame it was presed on

#

GetKey is all the frames its held on

indigo mirage
#

its fine, thanks for the help

half forum
#

Could it be that I installed it incorrectly or that there was a problem during the installation of Unity?

#

Also tried with different versions

rocky canyon
#

id have to research

mint imp
#

im trying to add a stamina bar to my game where if you dash, it sets it to zero and then it regenerates but for some reason it wont work

rich adder
#

which part is not working ?

half forum
mint imp
#

the fillamount doesent work

void thicket
mint imp
#

oh

rocky canyon
ashen umbra
#

i think ill die even before i reach to the programming part by watching u guys

mint imp
#

that explains it

#

lmao

ashen umbra
#

btw , by your exp.. Is progrmming hard ?

#

new to it

rich adder
ashen umbra
#

almost very much lmao

mint imp
#

it still doesent work

#

:/

rich adder
# mint imp

remove the -

float fillAmount = currentStamina / 100;
staminaBar.fillAmount = fillAmount;```
mint imp
#

aight

#

wait the one on line 18 or 19?

frosty hound
#

Think for a second. You're subtracting from the stamina because they took damage, so naturally not that one.

ashen umbra
#

what are these lines for ?

frosty hound
#

Whereas you're assigning a value to fill amount, but giving it a - sign. You don't want a negative value, of course.

rocky canyon
#

they're closing braces.. theres 1 for every opening brace

rich adder
#

time for c# courses

rocky canyon
ashen umbra
rocky canyon
#
function()
{
    if(thisthing)
    {
        // do something
    }
}```
ashen umbra
summer stump
frosty hound
#

This isn't the place to ask extremely basic questions, that's not how you learn. Do the tutorials/resources and actually learn.

ashen umbra
mint imp
#

@rich adder it still isnt working :/

frosty hound
summer stump
frosty hound
mint imp
#

yea

frosty hound
#

Is your image set up to work with fill?

mint imp
#

how do you do that

frosty hound
#

How did you do that?

mint imp
#

wdym

frosty hound
#

How was your image component configured?

mint imp
#

well

ashen umbra
mint imp
#

gime a sec

frosty hound
#

It isn't. You need to give it a source image, and change the type to fill.

mint imp
#

like this?

rich adder
#

do it in the inspector

#

put this in there (right click save)

mint imp
#

can yall hop in wild streaming and show me rq i dont really understand

fickle plume
# ashen umbra il check it right away , thanks

Best way to learn Unity is through Pathways courses on Unity Learn. Learning C# basics first would be very beneficial as well. Also with rare exception of one or two very comprehensive course series on YouTube you would be better off finding an interactive or written course with practical examples and exercises.

rich adder
mint imp
#

ok thx

solemn grove
#

Ignore this...

mint imp
#

oml it works now tysm

ashen umbra
summer stump
ashen umbra
#

😅 oh , i thought i made brother mad

mint imp
#

i have a question tho

#

would there be a way for me to ease in the stamina change?

queen adder
#

I am getting an error its in the screenshot this used to work fine now it doesnt no idea why anybody know why its with the Input.



{   
    public float speed = 5.0f;
    public float speedx;
    public float speedY;
    public float Health = 10.0f;
    Rigidbody2D rb;
    private Vector2 spawnLoc;
    public Transform player;
    public Vector2 playerPosition;
    public GameObject transition;
    public GameObject enemySpawner;
  

    // Start is called before the first frame update
    void Start()
    {
        spawnLoc = new Vector2 (-7, 1);
        Health = 10;
        rb = GetComponent<Rigidbody2D>();
       TransitionScript script = transition.GetComponent<TransitionScript>();
        EnemySpawner enemyspawner = enemySpawner.GetComponent<EnemySpawner>();
    }

    // Update is called once per frame
    void Update()
    {
     
        speedx = Input.GetAxisRaw("Horizontal") * speed;
        speedY = Input.GetAxisRaw("Vertical") * speed;

        rb.velocity = new Vector2 (speedx, speedY);
       getPlayerPos();
        if (transform.position.x > 8)
        {
            player.position = spawnLoc;
            EnemySpawner enemyspawner = enemySpawner.GetComponent<EnemySpawner>();
            TransitionScript script = transition.GetComponent<TransitionScript>();
            StartCoroutine(fadeInFadeOut());
            enemyspawner.nextWave();
          
        }
    }
    
    void TakeDamage() 
    {
      
    }
    public void getPlayerPos()
    {
       playerPosition = player.transform.position;
    }
    public void nextWave()
    {

    }
    IEnumerator fadeInFadeOut()
    {
        TransitionScript script = transition.GetComponent<TransitionScript>();
        script.fadeIn();
        Debug.Log("Faded In");
        yield return new WaitForSeconds(1);
        script.fadeOut();
        Debug.Log("Faded Out");
    }   
}```
languid spire
queen adder
#

I fixed it i see it now whoops

rocky canyon
#

which Input u want?

queen adder
#

yo could i use probuilder with blender models?

rocky canyon
#

you can probuilderize the model and then it can be modified w/ probuilder

queen adder
#

Anybody know How would I wake a TMP text equal an int or float of another script?

slender nymph
#

do you perhaps mean you wish to set the text property of your TMP_Text object to the value of that int or float? if that is the case, you simply need to get a reference to the object with that value you wish to use on it and assign to the TMP_Text's text property

devout turtle
#

Hello I am having a problem that produces no error. I am using a navmesh agent, and have set points that an ai needs to go to. once it reches a certain point though it just stops and wont go to the next point unless I move it past a nonexistant line, but it starts moving again if I move around the floors with navmesh surfaces and goes along without a problem until it needs to go back to the second point. Does anyone know how to fix this?

slender nymph
#

show relevant code as well as the settings on the navmeshagent component

devout turtle
slender nymph
#

!code

eternal falconBOT
devout turtle
slender nymph
#

you have a lot of nested if statements. have you done any actual debugging to find out if the conditions are evaluating to what you expect?

devout turtle
#

Yes and found absoutly no errors

slender nymph
#

what did you do to actually debug any of that? because you don't have any useful logs in the code

devout turtle
#

I did have them than rage quit without saving there was a travelling and arrived debug

slender nymph
#

that does not sound like useful information that would tell you what your conditions are evaluating to

cold carbon
#

hello guys ,where i can find good pathway to learn VR?

slender nymph
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

cold carbon
slender nymph
#

okay, so use the unity learn site which the bot conveniently linked after i used that command

queen adder
# slender nymph do you perhaps mean you wish to set the text property of your TMP_Text object to...

This is my code the errer is waveText = waveText.text = enemySpawner.Wave; says I cant convert int to string is there a way I should be doing this

public class waveTextScript : MonoBehaviour
{
   public TMP_Text waveText;
   public EnemySpawner enemySpawner;
   // Start is called before the first frame update
   void Start()
   {
       EnemySpawner enemyspawner = enemySpawner.GetComponent<EnemySpawner>();
   }

   // Update is called once per frame
   void Update()
   {
       
   }
   void updateWaveCounter(int wave) 
   {

       waveText = waveText.text = enemySpawner.Wave;
   }
}```
steep rose
#

first off you are using 2 = signs which is a no go

slender nymph
#

well for starters, that waveText = at the beginning of the line is almost certainly incorrectly.
as for what you are asking about, have you googled it yet?

cold carbon
slender nymph
#

i don't see why that is relevant

steep rose
#

you could do waveText.text = enemySpawner.Wave;

#

i have zero clue if that would work

cold carbon
#

i wanna ask a question

steep rose
#

bc i dont have your code

slender nymph
cold carbon
slender nymph
#

then ask it. did you not bother reading the information in the link i sent about asking questions?

willow scroll
cold carbon
slender nymph
cold carbon
devout turtle
#

I have set some proper debugs now and it is just saying that the destination is set and it still just not moving

slender nymph
#

show your current code and what is being printed

devout turtle
steep rose
#

that nesting is a mess

devout turtle
#

If you need to know the debugs popping up are the cooldown messages and the set destination

slender nymph
#

i did specifically ask you to show the logs being printed

#

but you're also missing some useful information such as whether the agent is stopped and its current position and distance to the destination

devout turtle
#

How should I write that up

hot palm
#

I have a class PlayerMovement with the following code snippet:

private void ResetMovement(bool enteredEditMode, Transform editorArea)
{
    [...]
    if (enteredEditMode)
    {
        if (lastEditorArea != null)
        {
            lastEditorArea = editorArea;
            transform.position = lastEditorArea.position;
        }
        else
        {
            transform.position = transform.root.position; // <-- Error in this line
        }
    }
    [...]
}

I get the error:
MissingReferenceException: The object of type 'PlayerMovement' has been destroyed but you are still trying to access it.
How does this have to do with the existence of PlayerMovement? Why should it be destroyed at this point? It even sets the position, but still gives me this error.

#
GameManager.Event_ResetPlayerToLastEditArea += () => ResetMovement(true, lastEditorArea);
#

This is how I call it btw, Copilot suggested it, is this wrong?

slender nymph
#

your event is probably static and you never unsubscribe from it. so when the scene is reloaded the new object subscribes to the event and that one probably works fine, but then the event still tries to call invoke the method on the destroyed object afterwards

hot palm
#

Oh I did see it work just fine once after recompiling

#

I only unsubscribe in OnDisable

#
private void OnDisable()
{
    GameManager.Event_ResetPlayerToLastEditArea -= () => ResetMovement(true, lastEditorArea);
}
slender nymph
#

that is unsubscribing a completely separate lambda expression. each time you create a lambda expression it creates a new instance of it. even if it is identical. You need to store the expression in an Action typed variable in the class, then subscribe and unsubscribe using that variable

#

or write a method that calls that ResetMovement method and takes no parameters and just (un)subscribe with that

hot palm
#

Ah I see, working with expressions you don't understand anything about should be doomed to fail. I'll just sub and give it a method, then call that with those values

#

Exactly what you just suggested, thanks a lot!

timid quartz
#

I am trying to create a sprite at runtime that turns an image red.

        int imagewidth = (int)TheMap.rectTransform.rect.width;
        int imageheight = (int)TheMap.rectTransform.rect.height;

        // create a texture with the same dimentions
        Texture2D maptexture = new Texture2D(imagewidth, imageheight);

        // make a color array of appropriate length
        Color[] BackgroundColor = new Color[imagewidth * imageheight];

        // fill the array with nothing but red
        for (int i = 0; i < BackgroundColor.Length; i++)
        {
            BackgroundColor[i] = Color.red;
        }

        // set the texture to use the color array, starting at 0,0 and continuing across the whole image
        maptexture.SetPixels(0, 0, maptexture.width, maptexture.height, BackgroundColor);

        // set the UI image's sprite to a sprite made from the newly colored map texture
        TheMap.sprite = Sprite.Create(maptexture, new Rect(0.0f, 0.0f, maptexture.width, maptexture.height), new Vector2(maptexture.width / 2, maptexture.height / 2));```

However, it appears to simply be making a transparent white sprite instead of the solid red I'm looking for.
eternal falconBOT
deft grail
devout turtle
#

Sorry it took so long I have added a moving debug here is the new version of the script and it is sending the debug not moving

timid quartz
#

oops I'm a dummy, had to send the texture to the GPU

#

after the setpixels

#

thanks all!

obsidian granite
summer stump
#

There are far better resources, so there is no reason to ever warch those ones

#

Their intermediate/advanced or specific ones are fine

frosty hound
#

The issue is beginners do not know what they're doing.

obsidian granite
#

i thought you meant in general

#

they were bad

summer stump
obsidian granite
#

and docs are extremely hard to parse through for beginners, no?

#

i feel like if i didn't know how to code, reading through docs (which inherently require SOME knowledge of OOP, given the fact that they reference inheritance trees, methods as members of classes, etc) would just leave me discouraged

summer stump