#💻┃code-beginner

1 messages · Page 53 of 1

reef patio
#

i dont see it used

#

aside from the script

silk night
#

Then how did you expect your player to move?

reef patio
#

i assume the script would have controlled a trigger to the input system

#

is there a seperate script needed for move composite?

#

i cant seem to find one in here

silk night
#

I mean yes you read the input from the InputSystem, but you dont do anything with it

reef patio
#

my input reader i added to the player

#

it has a character controller / animator and input reader which has the move composite code in it

halcyon hearth
#

I solved it, what I was looking for was Sort Group for whoever needs it, you can put the children on any layer, and they will all act as if they were on layer 2. And sorry for not using the correct channel xd 🐱

silk night
reef patio
#

ill check my components

#

i dont have one

frosty flicker
#

with GetComponent<>() does it only look for the current object and is there a way to search the entire scene

polar acorn
reef patio
#

how do i create a move composite?

silk night
#

you already have it

#

you just need to pass it to the Playercontroller

reef patio
#

ok how do I do that?

frosty flicker
polar acorn
timber tide
#

You can use GameObject.Find() then find the object then do a component search

#

it's fine for singleton stuff

#

and loading the scene

#

outside of that yeah, you wouldnt use it

polar acorn
#

If it's a singleton, you shouldn't need to use any sort of finding. Even then, you should be using find of type, not find by name

silk night
timber tide
#

Doing find by GO would be quicker I think, no? It cuts down searching through each GO

polar acorn
timber tide
#

I don't do it, but I assume that's the reason you'd use find at all.

polar acorn
#

FindObjectsOfType takes just as long as Find

frosty flicker
#

Im coding my GaneManager RN and wondering if and how i should make it a singleton or if ive already done it right

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameManager : MonoBehaviour
{
    public NightManager nightManager;
    public float powerDrainModifier;
    public GameManager Instance;
    // Start is called before the first frame update
    private void Awake()
    {
        Cursor.visible = true;
    }

    public GameManager() {
        Instance = this;
    }

    private void Start() {
        
        powerDrainModifier = nightManager.BasePowerDrainModifier;// + addedPowerDrain ;
    }

    private void FixedUpdate() {
        nightManager.Power -= Time.fixedDeltaTime * powerDrainModifier;
    }

    void OnEnable() {
        nightManager.HourChange += OnHourChange;
        nightManager.PowerChange += OnPowerChange;
    }

    void OnDisable() {
        nightManager.HourChange -= OnHourChange;
        nightManager.PowerChange -= OnPowerChange;
    }

    void OnHourChange(int currentHour) {
        Debug.Log("time changed! It's now " + currentHour);
    }

    void OnPowerChange(float Power) {
        Debug.Log("Current Power: " + Power);
    }
}
silk night
#

use Start/Awake

frosty flicker
reef patio
#

reopen the script?

silk night
#

yes, and check if the Instance already exists maybe

reef patio
#

and add that code to it?

silk night
frosty flicker
#
if (Instance == null) {
    Instance = this;
}
polar acorn
frosty flicker
#

is it this or am i checking not null my brain is sleeping rn

silk night
#
Instance ??= this;
polar acorn
silk night
#

Oh my bad, forgot about that

polar acorn
#

For example, if it's destroyed but hasn't been cleaned up yet

frosty flicker
polar acorn
silk night
reef patio
silk night
# reef patio

As I said its just code snippets that you need to fit into your Code

polar acorn
reef patio
#

i did not

#

i typed it in my self

polar acorn
#

That was supposed to be an example

#

you were supposed to read it and apply it to your own code

reef patio
#

i typed it in myself

polar acorn
#

It doesn't magically work just because you put in the keystrokes

reef patio
#

i sighted it and typed it myself

polar acorn
#

It doesn't magically work just because you put in the keystrokes

reef patio
#

lol

#

oh my god he showed help so I did it myself but probably not right

#

its incorrect man

#

see the red lines?

polar acorn
timber tide
reef patio
#

i need it solved

frosty flicker
#

considering they could just leave you to suffer on your own

reef patio
#

how do you sense my aggression in a chatroom?

#

i may be doing something

frosty flicker
#

you can tell by the way people type

reef patio
#

its subliminal

#

don't mind it so much

#

see where it leads to is a conflict of speech in the computer alike to caps lock conversations

polar acorn
reef patio
#

keep at ease, be calm, nice, on the computer, and you will succeed

frosty flicker
reef patio
#

i am 🙂

frosty flicker
#

although it is very obvious what the problem in your code is

summer stump
reef patio
#

yes, i can try to do it again

frosty flicker
#

[...] was just to show the rest of your code not for you to type as well

reef patio
#

ok one moment

#

its not coming out correct

summer stump
reef patio
polar acorn
# reef patio

Again, you were supposed to see the example and apply it to your own code. Not plop it directly into your code just wherever

summer stump
reef patio
#

im in one but im doing this on the side at the moment

#

i think I can progress

#

tests and stuff

#

or i may just have to wait until my class is finished

frosty flicker
reef patio
#

i understand I can be more confident with this

frosty flicker
#

But i would more focus on learning to read basic errors that litterally spell out for you what is wrong

reef patio
#

this website is what i used to get this far

summer stump
reef patio
#

where at?

summer stump
reef patio
#

i became a junior

#

but ill look back

#

thanks

supple wasp
#

How can I make code that clones a scene

#

From one scene to infinity

reef patio
polar acorn
reef patio
#

ttyl good bye

polar acorn
#

What are you trying to accomplish with that

supple wasp
polar acorn
supple wasp
#

So I can make animations

#

and modeling

polar acorn
#

But why do you need to clone a scene specifically

supple wasp
#

I just don't know how I can make code to create animation projects.

polar acorn
#

I have no idea how any of this relates back to needing to clone a scene

supple wasp
#

I already put a button where it makes projects

#

But the code is missing

polar acorn
#

I'm completely lost as to what you're even asking about any more

summer stump
# reef patio

Then I would say do the other course I said. That is for C# with no Unity

swift stag
#

Hello, I am trying to fix this error that is showing up on my console

#

It says it has something to do with the 'SaveManager

#

I have looked up the location in the code but don't know what to do here

#

It says it's located around line 343

summer stump
#

Also, is your IDE configured? Looks like no

swift stag
#

It's listed in the 343 line of WeaponController

summer stump
swift stag
#

Only thing I am seeing in the search are SaveSystem scenes

#

Is this a script or component you are referring to?

teal viper
#

Why do you not know what scripts there are in your project?🤔

swift stag
#

I'm using Universal Shooter Kit

#

I am trying to figure out how it works

teal viper
#

Okay, so you didn't write that code?

swift stag
#

no

summer stump
teal viper
#

Then perhaps that asset has a dependency that you didn't install.

summer stump
eternal falconBOT
teal viper
tiny leaf
#

in terms of conventions which order is preferred?

public static new

or

public new static
tiny leaf
#

in my case I needed to

teal viper
#

That would shadow out a field from a base class I guess.
Rarely would you need something like that for static variables. The convention is what you choose it to be.

polar acorn
tiny leaf
#
public new static AssetManager Instance
    {
        get
        {   
            if (_instance == null)
            {   
                _instance = FindObjectOfType<AssetManager>();
                if (_instance == null)
                {
                    _instance = (Instantiate(Resources.Load("AssetManager")) as GameObject).GetComponent<AssetManager>();
                }
            }
            return _instance;
        }
    }

Inheriting from generic singleton, but property needs to be slightly different

silk night
#

https://img.sidia.net/ZEyI5/jEVaFoFE86.mp4/raw

I have around 200 NavMeshAgents here, is there any way to make them "respect" each other more and get stuck instead of clipping into each other?

Currently using this:

        private void UpdateDestination()
        {
            if (!_hasTarget) return;

            var newPos = _followTarget;
            var currentPos = _lastPosition;
            // if (Mathf.Abs(newPos.x - currentPos.x) <= 1f && Mathf.Abs(newPos.z - currentPos.z) <= 1f) return;

            NavAgent.SetDestination(newPos);
            _lastPosition = newPos;
        }

Follow target is set every frame to the position of my player

sonic sphinx
#

Hello, I seem to be bouncing off what I feel ought to be a simple problem, and am hoping someone here might see something I don't.

Short version: I want to detect whether a 2D character is standing inside a "shadowed" area. I put shadowed areas on their own unique layer called "Shadows". Then, an ability script component on the character uses IsTouchingLayers to test against that layer like so:

        ShadowLayer = LayerMask.NameToLayer("Shadows");

        InHidingArea = this.gameObject.GetComponent<BoxCollider2D>().IsTouchingLayers(ShadowLayer);

Unfortunately, this always returns as FALSE whether I'm in, out, or touching the edge, of a shadowed area. Any ideas of simple things I may be missing?

timber tide
#

Do the shadows have colliders

sonic sphinx
#

Yup! They have BoxCollider2D and Rigidbody 2D components. The colliders are marked as triggers; don't know whether that matters.

timber tide
#

I'm not too sure but the method doesn't say anything about that.

reef patio
#

Im connecting some script for a player controller model, does anyone know how to solve this?

sonic sphinx
#

Yeah I didn't see anything in the documentation; it defaulted that way and I hadn't switched it off.

reef patio
#

Im connecting some script for a player controller model, does anyone know how to solve this

timber tide
#

Could try just boxcasting around the player and see if that returns any different results.

sonic sphinx
#

Does the Character have to be on the same layer as the Shadow objects? I had been assuming not given that IsTouchingLayers accepts a layermask of multiple layers, which made it seem perfect for checking overlap.

#

Okiedoke, I'll have a look at that. Thanks for the suggestion!

silk night
reef patio
#

I need the support from this channel, don't direct me to one, I have one already.

timber tide
#

This is less of a unity problem and more of a general c# problem honestly

polar acorn
reef patio
#

Can you guys not gang up on me? I need to finish this script.

#

One moment.

timber tide
#

Google or even clicking the error code will give you your answer instantly

reef patio
#

Check this script from Unity, it has a portion shown, it does not function.

#
Unity Learn

In this tutorial, we’ll dive deeper into Unity Cameras with scripts that control their behavior. We’ll start out with a 2D Camera that works from any perspective (in this case, we’ll be using it in an overhead view). Next, we’ll move on to 3D with a Camera that smoothly transitions — with a flick of the mouse scroll wheel — from first-person to ...

silk night
#

well thats because you copied code again without even trying to understand what it does

reef patio
#

I understand what its suppose to do, but the code is not functioning.

#

Maybe I am at error?

#

or he is the code creator

timber tide
#

Figure out the code error then revise what you've typed

polar acorn
reef patio
#

No I did do it myself, and then tried copy and paste after, and both failed to work.

timber tide
#

Seems like you typed it and that's good practice, but if you figure out the error code, you'll notice your mistake

reef patio
#

this part

#

"(currentDistance + maxDistance * 0.5f), updateSpeed * Time.deltaTime);"

#

"maxDistance" doesn't apply to it

timber tide
#

Ignore that, what is the error code. What does it mean -_-

polar acorn
reef patio
#

it means the max distance to travel in the game play of the camera controller player

#

like a measured street cross walk

polar acorn
timber tide
#

there I linked it for you

polar acorn
#

What type and where is it defined

timber tide
#

The low res picture doesn't help but I see the error

#

so revise the code and connect the error to it

reef patio
#

one mement

#

ya ill do that

#

brb

summer stump
# reef patio brb

Look at the name of the second variable in your code, and compare that name to the variable you tried to use

Also, count your curly braces. Every opening one requires a closing one

livid condor
#

Is this the channel for questions? I read the “read-me” channel and it was under the heading “scripting”

summer stump
#

Almost all the channels are for questions

livid condor
#

oh okay, I searched for a few minutes for a proper channel for my question and it’s not associated with coding but with unity itself

livid condor
#

thank you

queen adder
#

anyone know why this text pops up after importing from blender to unity? animations wont play either, it's just a simple raise shield animation

teal viper
#

Not really a code question btw.

sonic sphinx
#

Forgive me if this is obvious, but a bit of searching the manuals hasn't helped so far:

If a method takes a Physics2D.LayerMask as a parameter, are the layers defined by this layermask the same as the GameObject layers that one sets in the upper-right corner of the inspector?

Or is it a different set of layers, in the same fashion that Sorting Layers are different from GameObject layers?

timber tide
#

Layers in the top right are for the most part used for physic based operations like raycast and collisional checking. Sorting layers for 2D spriterenders is specifically for rendering ordering of sprites which is technically z-depth sorting.

teal viper
#

And yes, it's the layers that you can assign at the top right of the GameObject

wary sable
#

how would I go about acessing asset files from a script that I can run outside of runtime. I have a bunch of combat animations that I need to make override controllers / SO's for and would like to speed it up by writing a script. I just dont know how to do it in unity

sonic sphinx
#

Groovy, yes I knew it was a bitmask... I just wanted to make sure I wasn't trying to pass in stuff from a completely different category- I made that mistake the first time I was trying to find out how sorting worked, heh.

Thank you both!

teal viper
summer stump
sonic sphinx
teal viper
#

You can also do some bit shifting if you're interested.😏

summer stump
timber tide
#

It's actually the one time I prefer string operations because of that

teal viper
#

Bit masks are really cool actually. They're like mini bool arrays that are not restricted anywhere(like jobs or ECS)

timber tide
#

I use bit enums everywhere and unity surprisingly has editor support for them

feral palm
#

anyone help me with this error?

reef patio
#

ok i have it working now

#

thanks for the support

feral palm
reef patio
#

about the player controller

north kiln
# feral palm

Do you have autocomplete and error highlighting in your IDE?
Because I can't see where the error is supposed to be—have you saved?

feral palm
#

I do have error highlighting

#

Idk why it don't shoe

#

When I double click on the error in unity

summer stump
north kiln
#

and show the full stack trace

feral palm
#

It's brings me to the line where I instantiate created arrow

vague oyster
#

I need some help. I have a game that i finished and i built in WebGL and everything was fine in unity but when i uploaded it on itch.io most of my UI elements and assets were out of place, not at all where they should be. I have set all my canvases to "Scale with screen size" etc, someone who has had the same issue and knows and tips and tricks?

languid spire
vague oyster
languid spire
vague oyster
#

should i put Match to 0.5? or is 1 correct?

languid spire
#

0.5 is better, so the most accurate width or height can be used

vague oyster
fossil drum
languid spire
#

even better you can run the WebGL build locally and then play with the browser window size

languid spire
#

yes

vague oyster
# languid spire yes

i had trouble with compressed something something but i check "Decompression fallback" in publish settings, if that is the right way

#

because before i did that i couldnt even play it on the browser

junior seal
quiet gazelle
#

I am using the new input system, where i have an action set up for mouse clicks. in my inventory panel i want to figure out if the character preview (which is a raw image that shows a rendering texture) was clicked. how can I check that?

solemn fractal
#

Hey guys, in a scriptableobject script. I create a cs Public Sprite sprite; Variable, but in inspector there is no option to select the basic ones like, circle, box etc. How do I do it?

solemn fractal
frosty flicker
#

click that and they might be there

solemn fractal
#

OH,

frosty flicker
#

its a big might idk if it is

solemn fractal
#

yeah its there..

#

thank you

frosty flicker
#

np

quiet gazelle
hollow bloom
#

i have an problem. I have a game with different levels but when i play level 2, die and click on retry the game sends me back to level 1

ruby python
hollow bloom
#

public void Retry()
{
SceneManager.LoadScene("Level " + StateNameController.CurrentLevel);
}

#

public void Retry() { SceneManager.LoadScene("Level " + StateNameController.CurrentLevel); }

#

public static int CurrentLevel; here's from the StateNameController Script

#

public void OnButtonPlayGame() { SceneManager.LoadScene("Level " + LevelSelected); CurrentLevel = LevelSelected; } and this is when i choose the level

ruby python
#

!code

eternal falconBOT
ruby python
#

Okay either of these should do what you want.....

SceneManager.LoadScene(SceneManager.GetActiveScene().name);
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
#

Instead of giving it a ' hardcoded' value, just get what scene is currently open and load that.

hollow bloom
#

the game over screen is a seperate scene

#

it doesn't work

ruby python
#

Okay, I think, in your Retry method, before loading the scene you need to 'store' the current scene somewhere. (is your statename controller script accessible across all of your scenes?

hollow bloom
#

how do i know?

ruby python
#

Umm. If you wrote it, you should. 😕

hollow bloom
#

oh

hollow bloom
sage mirage
# junior seal Hey Im making a first person shooter and once i get finished killing all the ene...

Hey! That errors are very common errors. You can check this link for solution
https://forum.unity.com/threads/nullreferenceexception-object-reference-not-set-to-an-instance-of-an-object.1511555/

sage mirage
#

Everytime, you don't know how to solve an error just go to forums and make a topic or see other topics from people handling the same error. Of course, you can ask whatever you want here to find solution to your issues 🙂

azure zenith
#

I need assistance

#

Please and thanks

frosty hound
azure zenith
#

I have an issue with Unity, my player will not move forwards when I press W, it will go in random directions

#

Sometimes it will, sometimes it will not

frosty hound
#

And ... are you going to show how you did it?

languid spire
#

Now imagine someone else had asked this question, how would you go about answering it?

azure zenith
#

I am not too sure if it is a hardware issue

#

It does work sometimes

frosty hound
azure zenith
#

What is this in my scene?

frosty hound
#

A blue square. Not a coding question.

solemn fractal
#

Hey guys, I have a ScriptableObject. and I have 3 enemies. When I change the color of the enemy or the scale it works. But what about the sprite? I want one enemy to spawn with a isometric diamond shape and the other with a circle. But I am not being able to figure it out on start method, what should I write. Here is example of how I am doing with the color and scale.

#
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        _player = FindObjectOfType<Player>();

        // change the color of the experience to the SO Color
        _spriteRenderer = GetComponent<SpriteRenderer>();
        _spriteRenderer.color = data.color;
        // change the scale of the experience to the SO Scale
        _scale = transform;
        _scale.localScale = data.scale;
        // change the sprite of the experience to the SO sprite
        _sprite = GetComponent<Sprite>();
        
    }
``` But for the sprite I am not sure how to do it.
eager elm
solemn fractal
#

I did like that cs // change the sprite of the experience to the SO sprite _spriteRenderer = GetComponent<SpriteRenderer>(); _spriteRenderer.sprite = data.sprite;

#

but it is not working

#

Now its working thank you

plain hound
#

ok i found a better way to explain my question

frosty flicker
#

Trying to look at what

yield return new WaitForFixedUpdate();
``` Does and i cant find any good explainatons does it just do the stuff in the while loop on fixed update
plain hound
#
        t = Mathf.Lerp(t, 1, t);
        t = Mathf.Lerp(t, 1, t);
        t = Mathf.Lerp(t, 1, t);```
basically i can make a polynomial of any order by adding more mathf.lerp, but i wanted to know if unity has built in polynomial functions
#

linear, quadratic, cubic, quartic, quintic

keen dew
#

What are you trying to do? Raise t to some power?

plain hound
#

i just want to make polynomial curves basically

#

like a bezier curve is a cubic polynomial iirc

eager elm
plain hound
#

which you can do with adding more lerps, but i wonder if there's a nicer way, like a polynomial function

frosty flicker
#

nvm this is not working as intended

verbal dome
eager elm
chilly moss
#

can someone help, my character is refusing to move right

eager elm
# chilly moss

use Debug.Log("Some Text"); to figure out which of the if statements is getting called.
You can also use Vector3.right instead of .left * -1

frosty flicker
wintry quarry
#

Power = TotalPower right before checking if Power< TotalPower

#

The FixedUpdate way would have been more consistent BTW.

frosty flicker
wintry quarry
#

Neither would work at all

frosty flicker
#

well i mean at the start of course the power would be the total power

#

oh shit doesnt it need to be <=

eager elm
#

you probably want while (Power > 0)

frosty flicker
#

also dont kill me for having capital letters for variable names plz

frosty flicker
keen dew
#

It shouldn't be WaitFor anything. Just yield return null and multiply the change by deltaTime

frosty flicker
#
public IEnumerator RunGame() {
    Power = TotalPower;
    while (Power > 0) {
        HasPower = true;
        yield return null;
        Power = Power - (BasePowerDrainModifier + AddedPowerDrainModifier) * Time.deltaTime;
        PowerChange(Power);
    }
}
queen adder
#

almost thought something like this would work

keen dew
#

depends on what you're expecting it to do

verbal dome
#

haha would be a Coroutine, not an IEnumerator here though

#

What do you need the reference for?

wintry quarry
queen adder
keen dew
#

What does the IEnumerator have to do with "extra logic"? Are you trying to start a coroutine?

floral wren
hallow badger
#

Is there away get my coding coloring in vc because it all flat same colour. Never use virtuele code community

eternal falconBOT
hallow badger
normal arrow
#

Hi guys ! i'm using two unity app linked by tcp-udp connection, and i need to reload both current scenes, i was wondering if, by doing the basic reload, the udp-tcp connection cut instantly or if i have something else to do

wintry quarry
normal arrow
#

yeah so but reloading it nothing will change in terms of connections right ?

wintry quarry
#

I have no idea

#

it depends on your code

sullen parcel
#

does anyone know how you get f.e. the rotation inputs in your script?

finite star
knotty gull
#

hello
need to create a mesh from point 1 to point 2
i already did the line renderer solution, need another solution with creating a mesh, anyone got an example of this?

sullen parcel
# finite star What do you mean by rotation inputs?

well In the transform object you have the 3 rotations input on one line. Im assuming its also in one object so you can get the values like Object.x, Object.y, Object.Z Im not sure what I need to put to get the same results. Normally inputs are put under each other.

finite star
sullen parcel
#

I want to put multiple coordinates on my object so I can access them later

#

I want to pre define the coordinates

#

ah yea, Quaternion is what I looked for

#

thanks

sacred lake
#

How do I allow a timeline to contain multi-scene references?

tardy pawn
wintry quarry
tardy pawn
#

sorry im very new where would i put it to make sure its right?

wintry quarry
#

well you're concerned about the jump right?

#

So for example inside the if statement on line 37 would be a really good spot

solemn fractal
#

Hey guys.. I have a situation here I am a bit stuck for the past 2h, and seems to be easy and I managed to make it work in another small game I made before. But now for some reason is not working. So I have a UImanager where I show text in the screem basically update the text in the UImanager with the actuall player exp.. when the player experience increase when I get experience in the map it works as the Debug.log I have after the player get the exp shows the exp is correct and it is increasing, but when I try after that increase to add that to the text in the UI doesnt work. ANy ideas just by looking to those SS ?

polar acorn
#

Actually, looking at it, there's basically no way you don't have an error.

#

Check your console

solemn fractal
#

i dont have error

polar acorn
solemn fractal
#

the debug log shows 0 always

#

so for some reason its not working

#

and That I already know

#

that is why I asked here why that could be happening 😛

polar acorn
#

Ah, wait, I missed the [SerializeField] sorry, I just woke up

solemn fractal
#

all good 😄

#

and I am already in unity for the past 10h

#

so I might not be seeing something easy

#

to spot

buoyant knot
#

i don’t understand the issue

#

it shows the wrong text, or it shows no text, or the text doesn’t change?

polar acorn
#

So it seems whatever Player your UIManager references has no experience. Either GetExperience does nothing or you're calling it on a different Player

buoyant knot
#

also you shouldn’t store two values of exp that can get desynced

polar acorn
#

Or data.howMuchExperience actually is zero

solemn fractal
#

hmm ok i will check it better thank you

buoyant knot
#

if Debug.Log says experience is 0, then I would work backwards from why exp is 0

solemn fractal
#

yeah I am trying to do all the path and see if the order is correct.

buoyant knot
#

first, I would delete the experience field from the UI class

#

UI class should be reading EXP from a central spot

solemn fractal
#

hmm ok, make sense

buoyant knot
#

then go to the experience field for the player, and change it so you have a custom setter. Change the setter to give a Debug.Log whenever it gets called

solemn fractal
#

in Ui Manager I am asigning the player EXP to the experience variable so I can show it on the screen

buoyant knot
#

I know. Don’t save it as a field

#

UI manager already knows where to go read EXP because it has a reference to the player

solemn fractal
#

oh true

#

makes sense

buoyant knot
#

now in the player’s exp, give it a setter to debug.Log

#

like
private int _experience;
public int experience { get => _experience; set { Debug.Log(“Changing exp to “ + value; _experience = value; }}

#

this way you get notified whenever EXP changes

#

you should use that setter anyway so your UI can just know whenever exp changes

#

example:
public event Action OnEXPChange;

setter: if (_experience != value) OnEXPChange?.Invoke();

#

then UI manager can just listen to OnEXP change, so it can get updated whenever that value changes

solemn fractal
#

That is a bit advanced for me. But I will try thank you again !!

buoyant knot
#

you should learn events/Actions. they will make your life easier

solemn fractal
#

i will have a look into it for you. Thank you. I am going step by step otherwise I get crazy. But I managed to do it in another small game I was doing and worked in this one is not as its a bit bigger so prob is just a logic order that I am missing here

buoyant knot
#

example;

public event Action OnJump;
public void Jump() {
OnJump?.Invoke();
}
}

public class JumpDetector() {
[SerializeField] private PlayerMovement move;

void OnEnable() { move.OnJump += WeJumped; }
void OnDisable() { move.OnJump -= WeJumped; }

void WeJumped() => Debug.Log(“We Jumped!”);
}```
#

understand?

solemn fractal
#

yes understood now, Will try something here and let u know later if worked thank you again for your time

solemn fractal
#

instead of using serializedfiled and using the prefab on the inspector

mellow shuttle
#

it's the same thing so why is mine wrong

wintry quarry
#

look again

#

when you do it the same, it will work

mellow shuttle
#

no I don't see

summer stump
# mellow shuttle no I don't see

Look at every character
Do you see a comma in theirs after dir.normalized?

The quality is really bad so I can't tell, but are you using a ^ ?

glacial obsidian
#

Im a complete beginner in unity and im trying to make a simple clicking game with a cookie, i made a componenet for the cookie/coin and a script (using chat gpt) but for some reason the counter is not increasing even if i click on it

the script used:

using UnityEngine;
using UnityEngine.UI;

public class ClickerGame : MonoBehaviour
{
    public Text clickCountText;
    private int clickCount = 0;

    private void Start()
    {
        // Initialize the click count and update the text.
        UpdateClickCountText();
    }

    private void UpdateClickCountText()
    {
        // Update the UI text to display the click count.
        clickCountText.text = "Cookies: " + clickCount;
    }

    public void OnClick()
    {
        // This method is called when the cookie is clicked.
        clickCount++;
        UpdateClickCountText();
        Debug.Log("Cookie clicked! Click count: " + clickCount);
    }
}
wintry quarry
#

code doesn't just run magically

glacial obsidian
#

is public void Onclick a function?

wintry quarry
#

It;'s a function you created

#

nothing more than that

glacial obsidian
#

oh alright thanks

gaunt ice
#

google "detect mouse click unity" or some keywords like this

glacial obsidian
#

p.OnClick();

glacial obsidian
ripe shard
# quiet gazelle thank you very much! although that system seems to be heavily focused on a mouse...

if you don't have a pointer you cant point at stuff and click on it, you can move a pointer with a gamepad's thumbstick or you can use the EventSystem's Selectable system and contextual NavLinks. Usually you either completely separate mouse & gamepad control-scheme from each other or make a control-scheme that works for both with 1:1 input mappings, this means the mouse scheme would have not assume the existence of a pointer or you would make a joystick pointer for the gamepad scheme.

silk night
#

Hey, trying to wrap my head around this problem for an hour now: https://img.sidia.net/ZEyI5/juzexafA38.mp4/raw

My bullets slightly appear at 0, 0, 0

My source code:
Spawner

    public GameEntity Instantiate(string resource, GameEntity entity = null, Transform parent = null)
    {
        [...]
        var gameObject = Object.Instantiate(Resources.Load<GameObject>(resource), parent);
        if (gameObject == null) return null;

        var view = gameObject.GetComponent<EntityView>();
        if (view == null)
        {
            Debug.LogError($"Spawned resource {resource} does not have entity script");
            return entity;
        }
        view.Link(Contexts.sharedInstance, entity, resource);
        [...]
    }

Bullet

        public override void Link(Contexts contexts, GameEntity entity, string entityName)
        {
            base.Link(contexts, entity, entityName);
            var pos = _entity.position.Value;
            var direction = _entity.direction.Value;
            
            Rigidbody.position = pos;
            Rigidbody.rotation = direction;
        }

Do I have to Instantiate with a position for this not to happen? I never had problems first instantiating and then moving to my desired position without the object blinking at zero first

wintry quarry
silk night
#

So its basically visible at zero for one frame if I dont?

wintry quarry
#

that being said I don't really see the issue you're describing in the video

silk night
#

Look a bit left and up from where my character starts

wintry quarry
#

got it

#

idk it's kind of unclear what's going on in this code

#

where does the Rigidbody reference come from

silk night
#

Its a public reference above, didnt want to paste my whole class as its a bit bigger

wintry quarry
#

oh nvm I see it must be assigned in the inspector

silk night
#

Yep

wintry quarry
#

A Physics.SyncTransforms() or transform.position = pos; may help too

silk night
#

Ill try

#

oof

#

I did either only rigidbody.position or transform.position

#

now i did both and it works like a charm

#

ill add in the velocity stuff again and look if it behaves as expected 😄

wintry quarry
#

would be cleaner/more performant though just to instantiate it there in the first place

silk night
#

Yeah i guess I will edit the instantiate function to check if the entity has a position entityComponent attached and pre-position instead of doing that in the Link function of every view 😄

wintry quarry
#

this is also a bit jank:

        var gameObject = Object.Instantiate(Resources.Load<GameObject>(resource), parent);
        if (gameObject == null) return null;```
#

gameObject will never be null here but Resources.Load<GameObject>(resource) might, and in that case you'll get an error

silk night
#

Oh, thanks, I'll edit accordingly

wintry quarry
#

instead of all the GameObject / GetComponent stuff

silk night
#

EntityView is the parent class for all EntityViews

#

Oh wait, thats what you mean

#

got it, ty

dawn sparrow
#

I got a question about memory
So since we can't contain contain references to a single bit, and instead must use BitArray, how many bits are used for each bit in a BitArray?
Sorry that's a mouthful, my goal is to have a barebones way of storing bits where each additional indice means 1 additonal bit in memory'

dawn sparrow
buoyant knot
buoyant knot
#

you should get passed the reference in some way

#

GetComponent, or SerializeField, or a Singleton that has the reference

dawn sparrow
#

Please use a pastebin for large chunks of code

buoyant knot
#

or a reference to something with the reference

silk night
#

How is your Player1/2Score defined?

dawn sparrow
#

!code

eternal falconBOT
buoyant knot
#

I made a singleton class with references to common important objects, like the player character

dawn sparrow
#

more than 1 or 2 lines should be shared using a pastebin

buoyant knot
#

FindObjectOfType is a big noob trap tho. Should avoid

green copper
#

!code

eternal falconBOT
green copper
#

I'm using this script for letterboxing, but I can't get the aspect ratio to change during runtime

#

RescaleCamera() is called in Update(), so changes to targetAspect should apply in real time as far as I can tell

wintry quarry
#

also are you using Cinemachine?

green copper
floral wren
wintry quarry
#

does it work on a basic camera (no cinemachine) in a scene on its own?

dawn sparrow
#

Reason why I'm trying to create a 5 byte array is in an effort to optomize memory usage of a voxel world
Each chunk is 32 by 32 by 32 so i only need 5 bit precision to describe any blocks position in a chunk

#

would prefer not to use any more than that if possible

silk night
# wintry quarry you can also just do `Resources.Load<EntityView>()` directly
    public (GameEntity, EntityView) Instantiate(string resource, GameEntity entity = null, Transform parent = null)
    {
        entity ??= CreateEntity();

        var loadedResource = Resources.Load<EntityView>(resource);
        if (loadedResource == null) {
            Debug.LogError($"Requested resource {resource} does not exist");
            return (entity, null);
        }

        var position = entity.hasPosition ? entity.position.Value : Vector3.zero;
        
        var view = Object.Instantiate(loadedResource, position, Quaternion.identity, parent);
        view.Link(Contexts.sharedInstance, entity, resource);

        return (entity, view);
    }

This looks better now? or still something I should change?

floral wren
#

Also, it is 1 byte, not 4 byte.

green copper
#

so I think I just need to add a || to the if statement that triggers updating the letterbox inside the script, probably

floral wren
#

sizeof(bool) returns 1 at least

sharp abyss
#

How Can I get the damage int and mesh of the weapon I pick up from the weapon I pick up
In this script https://hatebin.com/gilbfmrtcn I only make the sword child visible and delete the one I pickup

polar acorn
sharp abyss
polar acorn
#

You asked how to get a value from the thing you pick up

#

I'm telling you how to do that

sharp abyss
#

oh thanks I understood

#

but when I pick up it destroys the gameobject wouldnt that occur an error because there isnt a gameobject I can get the values from

polar acorn
sharp abyss
#

I'll try

azure zenith
#

I have found a script called CountDown which I do not remember making

#

Does anyone know why it is there? Is it something that is automatically there? I am thinking of removing it

summer stump
polar acorn
eternal needle
#

Time for a git blame

sharp panther
#

SCRIPT 1

private new Camera camera;
    private interactable Interactable;

    [SerializeField] private Texture2D Cursor1;
    [SerializeField] private Texture2D Cursor2;

    private Vector2 cursorHotspot;
    public void Start()
    {
        camera = GetComponent<Camera>();
        cursorHotspot = new Vector2(Cursor1.width / 2, Cursor1.height / 2);
        Cursor.SetCursor(Cursor1, cursorHotspot, CursorMode.Auto);
    }

    void Update()
    {
        Ray ray = camera.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out RaycastHit hitInfo))
        {
            if (hitInfo.collider.gameObject.GetComponent<interactable>() != false)
            {
                if (Input.GetMouseButtonDown(0))
                {
                    Debug.Log("tap");
                    if (Interactable == null || Interactable.ObjectID != hitInfo.collider.GetComponent<interactable>().ObjectID) //source of problem?
                    {
                        Interactable = hitInfo.collider.GetComponent<interactable>();
                        Debug.Log("newINT");
                        Interactable.onInteract.Invoke();
                    }
                }
                cursorHotspot = new Vector2(Cursor2.width / 2, Cursor2.height / 2);
                Cursor.SetCursor(Cursor2, cursorHotspot, CursorMode.Auto);
            }
            else
            {
                cursorHotspot = new Vector2(Cursor1.width / 2, Cursor1.height / 2);
                Cursor.SetCursor(Cursor1, cursorHotspot, CursorMode.Auto);
            }
        }
    }

SCRIPT2

public class interactable : MonoBehaviour
{
    public UnityEvent onInteract;
    public int ObjectID;

    // Start is called before the first frame update
    void Start()
    {
        ObjectID = Random.Range(0, 999999);
    }

}
#

I have been trying to sort this out for weeks and any help would be much appreciated, basically the interact will work once and will only work again if I interact with another object then come back to it

eternal falconBOT
sharp panther
wintry quarry
#

the ObjectID thing is totally pointless btw

#

you could achieve the same thing with Interactable != hitInfo.collider.GetComponent<interactable>()

sharp panther
#

Ill give it a shot

wintry quarry
#

i mean

#

that's not going to fix your problem

#

I'm just saying here's no need for that object ID scheme

#

since all of these objects already have ids

#

but the reason you can't interact twice is because you're doing that check in the first place

eternal needle
#

That object ID thing is pretty bad too. You will basically have a somewhat rare chance that your game breaks

wintry quarry
#

why are you doing that?

wintry quarry
#

looks like in this case a rare chance that the game works properly lol

#

I also don't recommend doing hitInfo.collider.gameObject.GetComponent<interactable>() over and over again, it's a performance waster

#

basically this whole if statement if (Interactable == null || Interactable.ObjectID != hitInfo.collider.GetComponent<interactable>().ObjectID) should be deleted

#

there's not really any need for it.

solemn fractal
silk night
#

So next problem for me... first time using World Space UI: https://img.sidia.net/ZEyI5/padepiQe40.mp4/raw

My healthbar is rotating with the monster, understandable that it happens, but whats the best way to fix it? If i put the NavMeshAgent on a child object to rather only rotate the mesh part the parent doesnt move at all anymore. I attached the structure of my Gameobject.

The only solution that worked for me was executing UI.rotation = Quaternion.Euler(30, 0, 0); on every Update but I feel like thats a hacky solution

sharp panther
#

IT DID!!!

#

WHOOO

#

I am genuinly so happy rn

wintry quarry
#

you can solve these problems on your own

sharp panther
timber tide
wintry quarry
sharp panther
wintry quarry
#

Sure throw me in

silk night
timber tide
#

Oh, you're using UI eh

silk night
#

Yeah, a World Space Canvas

timber tide
#

Ok, similar idea I had, but remove the navmesh from the parent and go down a child. Basically the parent is just a wrapper, and now you can have a sibling relationship to the HP bar.

#

but, you want to then update the position manually through script

silk night
#

then the parent doesnt move anymore, only the child object

#

In the case i might aswell keep resetting the ui rotation, same effect as setting the position manually every frame 😄

timber tide
#

The idea is to just update the rotation and position without having the hierarchy do it for you

#

and basically make all hp bars rotate relating to an object that doesn't rotate (the game manager) ;)

sharp abyss
#

I have a gameobject for my sword.its looking(mesh renderer) changes on conditions,but their rotations arent compatible ,like when rotation is 90 one is looking normal but other one does not look normal when it I put it in mesh renderer what can I do

short hazel
#

Seems like the different meshes were exported differently, if you used a 3D modelling software

#

You'll have to re-export them with identical export settings

wintry quarry
#

(not a code question really)

sharp abyss
frigid turtle
#

Hello!
I noticed that when I press a button and also check Input.GetKeyUp(KeyCode.Mouse0) in Update(), the button event gets called before the update where GetKeyUp returns true.
Do you think I can rely on that? (Will it always be in that order or is it random?)

buoyant matrix
#

I've got a zelda style hearts "life bar" to show health for a 2d game I'm working on. It starts as a single sprite, but is tiled and continuous. When I change the width, it grows to the left and goes off the screen, instead of growing to the right, and I was curious if this was something I could change in code (or somewhere else)? I'm setting the width correctly, I think... currentHealthRenderer.size = new Vector2(heartSize.x * fullHearts, heartSize.y);

wintry quarry
#

What button event?

rich adder
frigid turtle
wintry quarry
buoyant matrix
rich adder
frigid turtle
#

Hmm ok, thank you!

buoyant matrix
#

I don't see an anchor in the inspector? Am I missing something?

wintry quarry
#

What's the use case?

buoyant matrix
short hazel
#

Oh

wintry quarry
short hazel
#

It's not UI?

wintry quarry
#

this is not a UI element

rich adder
#

dang

wintry quarry
#

Did you mean to make it a UI element?

buoyant matrix
#

Ahhh. It should be a UI element.

rich adder
#

no wonder size is huge

wintry quarry
#

UI -> Image

#

not sprite

timber tide
#

You can make it work without UI, but then you're having to do some more manual work

buoyant matrix
#

No, I should have created it as a UI image. That makes more sense.

#

Thanks.

short hazel
#

Make UI > Anchor top-left, edit the Rect Transform's sizeDelta property

buoyant matrix
#

I figured it was something easy I was doing wrong.

timber tide
#

Another idea is instead of tiling a texture, just make multiple gameobjects per heart

buoyant matrix
#

That seems memory inefficient... I guess it's not that big a deal since the max number of hearts they would have is pretty low.

timber tide
#

it's so minor

#

unless we're talking minecraft here

buoyant matrix
#

We aren't. 😂

buoyant knot
#

but i like minecraft

#

everyone likes minecraft

#

every game should start by trying to be minecraft

timber tide
#

If your game isn't a single mesh with a single texture atlas then you're doing it wrong

buoyant matrix
#

So I've changed my sprite to an image... But I still have the same problem. And I'm not sure what that warning means...

rich adder
#

ur pivot is still in the middle

#

0.5 / 0.5

#

you prob want try X0 Y0.5

buoyant matrix
#

That was it. Thank you! I thought the anchor you were mentioning was the top left corner, not the pivot.

rich adder
buoyant matrix
#

I don't really understand the differences.. Was the thing I thought the anchor actually the anchor? (the part that says "top left")?

#

And is Anchor for deciding where the UI goes as you change resolution?

rich adder
#

yea Pivot is the origin point of the Image/rect
Anchor is where this element will be stuck when you shift resolution

buoyant matrix
#

Got it. And the origin point of the rect is where it will grow from if you change the size?

rich adder
#

pretty much yea

buoyant matrix
#

Thank you for the explanation! This has helped a lot. 🙂

azure zenith
#

Which folder should this go in?

finite star
ashen wind
#

when I add a child to a parent gameobject it changes the transform axis of the parent

#

how do i prevent this?

azure zenith
finite star
finite star
ashen wind
#

the red circle parent starts with its axis in the center

finite star
ashen wind
#

then when i drag the child in, its axis is now halfway between its own and the child's

finite star
#

its just changing the center

ashen wind
#

that's what i want to prevent

finite star
ashen wind
#

thanks

slender kelp
#

Hello,
Does anyone know if i can use _LightColor0 in Shadergraph?
When i add property with same name, not exposed, it says redefinition of '_LightColor0'

Anyone know a way around this?

slender kelp
#

whoops!

solid verge
#

hello, does anyone know any idea how to get a public float from another script in another game object. I've watched a lot of tutorials and yet can't find the solution to my problem.

wintry quarry
#

this is the most basic unity question asked hundreds of times per day. Those tutorials likely showed you many different ways to accomplish to part 1.

solid verge
#

yes but it doesn't help

#

the tutorials*

solid verge
#

i am sorry but i am stupid kid and i don't know what else to do.

wintry quarry
#

!ide

eternal falconBOT
merry spade
#

When I try to turn the cube in my touch direction it works, but the further i go the weaker the rotation is, the weird thing is when i delete the movement and let the rotation, it works fine.
Can you think of what the problem is?

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UIElements;

public class PlayerScript : MonoBehaviour
{

    [SerializeField] private Camera mainCamera;

    private Rigidbody rb;
    private float speed;
    private Vector3 tp;
    private Quaternion toRotation;
    void Start()
    {
        speed = 5f;
        tp = Vector3.forward;
        rb = GetComponent<Rigidbody>();
    }

    
    void Update()
    {
        if(Input.touchCount == 1)
        {
            Touch touch = Input.GetTouch(0);
            if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Began)
            {
                if (Physics.Raycast( Camera.main.ScreenPointToRay(touch.position), out RaycastHit hit, 40f))
                {
                    tp = hit.point;
                    tp.z = transform.position.z + 5;
                    tp.y = 0;
                    print(hit.point);
                }

            }


            
        }
        toRotation = Quaternion.LookRotation(tp, Vector3.up);

        transform.rotation = Quaternion.RotateTowards(transform.rotation, toRotation, 6f);


    }
    private void FixedUpdate()
    {
        rb.velocity = transform.TransformDirection(Vector3.forward) * speed;
    }
}
short hazel
#

It detected both the solution and the project

solid verge
#

i have 100mb space xd

short hazel
#

huh?

solid verge
#

computer space

#

disc space

wintry quarry
#

that's incorrect, leading to your issue.

solid verge
#

100 megabytes

short hazel
#

Doesn't matter?

solid verge
#

just sharing

polar acorn
merry spade
wintry quarry
merry spade
#

but not the right one

wintry quarry
#

why not

merry spade
wintry quarry
#

well it all depends what you do with that vector now doesn't it

#

for one I think you should be using Plane.Raycast here - not Physics.Raycast

#

and then just make sure you project the look vector on the XZ plane before creating your quaternion

#

or make sure your plane you chose for Plane.Raycast is at the same y position as your player object

merry spade
#

how do i project the look vector on the XZ plane?

merry spade
#

i dont really understand the problem of the code

wintry quarry
#

simple

#

it's making your object tilt up/down

#

then when you move "forward" it's moving up/down since it's tilting that way

#

by the way transform.TransformDirection(Vector3.forward) can just be written as transform.forward

merry spade
#

but why does the turning effect gets weaker and weaker?

wintry quarry
#

you're just looking at a point further and further away from the origin

#

hence a more and more straight look vector

merry spade
#

but in transform.position - tp it does it aswell

timber tide
#

could probably just freeze the tilt rotation and the direction would be fine with the raycast

wintry quarry
#

because you're also doing this: tp.z = transform.position.z + 5; which is likewise nonsensical

#

freezing the rotation on the RB will do nothing when you are manually changing the object's rotation

merry spade
#

this prevents it from going backwards

timber tide
#

ah, right then probably just set it to 0 in the script, eh?

#

Is it the y that's tilting?

wintry quarry
#

it also makes sure the vector is completely wrong

merry spade
#

why

#

no

wintry quarry
#

because the z psoition of the hit is extremely important

#

and you are overwriting it

merry spade
#

it just moves the z coordinate to a fix spot

wintry quarry
#

you could clamp it to the player's position. But don't just blindly set it

wintry quarry
#

actually Ok i see what you're saying

#

it can work

#

but you need to do the rest correctly

merry spade
merry spade
wintry quarry
#

e.g.
toRotation = Quaternion.LookRotation(tp, Vector3.up);
needs to be something like:

Vector3 dir = tp - transform.position;
dir.y = 0;
toRotation = Quaternion.LookRotation(dir, Vector3.up);```
merry spade
#

the plane.raycast could be a better way but with y = 0 im doing the same

wintry quarry
#

dir.y = 0; is a poor man's way of doing the plane projection

timber tide
#

hey now

wintry quarry
#

So the direction from not 0 to 0 is up or down

merry spade
#

no no its local

wintry quarry
#

there's nothing local about it

#

everything here is world space

merry spade
#

no

summer stump
wintry quarry
#

yes

merry spade
#

wait

wintry quarry
#

maybe that's part of your confusion

merry spade
#

guys let me talk

#

you see in the video that it doesnt look up or down

#

it works fine

summer stump
wintry quarry
polar acorn
#

You don't

wintry quarry
#

Start a coroutine inside it

polar acorn
#

OnTriggerEnter fires once when a collision begins

wintry quarry
#

In previous Unity versions OnTriggerEnter itself could be a coroutine, not sure if that's still possible

vague oyster
#

I am trying to queue up some animations i have, one or more animations can get triggered in my game but i want to queue them up so they play one after the other, right now if more then 1 is tiggered, it randomly plays only one animation, anyone know how?

fierce shuttle
wintry quarry
#

A special kind of function in Unity that lets you include delays (such as "wait one frame") inline in the code

polar acorn
wintry quarry
#

yes you can use deltaTime in a coroutine

#

you can use it anywhere you want

#

doesn't mean you'll be using it correctly 😉

vague oyster
polar acorn
#

Like A->B->C->A but you can start at any of A, B, or C?

timber tide
#

I guess you can just queue a bunch of animation clips

#

then poll the time remaining

vague oyster
timber tide
#

I mean I guess you can use the animator blend tree but I'd assume it's going to be a giant spiderweb

vague oyster
polar acorn
#

Oh, wait, I think I see

vague oyster
polar acorn
#

Lemme make a quick visual example, this is hard to explain in words

vague oyster
#

Can i link my game, its not published but you can still play it. And you will see what i mean

#

Like you see there, you can win if more then one symbol combo hits, and every combo has its animation but if more then one hits only one animation is played, so i want them to queue and alternate

timber tide
#

Just check if the animation is playing, and if it's not then iterate to the next.

polar acorn
#

Okay, so, "Landing" is a state with no animation on it. It serves only as a redirect to the proper A, B, C, etc. and for them to transition back to. The transition into Landing is when any of them are true, and the transition to each individual state is when that trigger is true. The exits happen when the animation ends and goes back to Landing. This means that if another "Letter Parameter" is true, it goes to that one right away.

What you need hear is a boolean parameter for if any of them are playing, and an individual Trigger parameter for each one. Triggers are un-set when they're checked so they'll take care of un-setting themselves. Now, you can set the triggers while one is playing and it'll hop into that one when the current one ends instead of checking the trigger early and hopping right into it

vague oyster
vague oyster
# polar acorn Okay, so, "Landing" is a state with no animation on it. It serves only as a redi...

Damn thats a excellent visualization and explanation, thanks for that! I have to admit one thing tho, i dont really use animator like that, with parameters directly in unity, i use code instead, but ill have try that because that was a great explanation. I can just send what code i use:

void ChangeAnimationState(string newState)
{

//stop the same animation from interrupting itself
if (currentState == newState) return;

// play the animation
animator.Play(newState);

// reassign the current state
currentState = newState;

}

#

so basically i call a animation in my code where i want it, just wanted to show but ye thanks again

oblique torrent
#

https://sourceb.in/rSPC1LRAa0

can anyone see whats wrong with this code? it was working until i closed and reopened unity 🤔
the code still shows the loading screen, loads the next scene and then hides the loading screen, however it doesnt wait 2 seconds

#

from what i can see everything looks fine

calm osprey
#

can I allow a method to begin only if a certain animation is playing?

oblique torrent
modest dust
real vapor
#

would the line velocity += transform.forward * acceleration * Time.deltaTime;
increase "velocity" (which is a Vector3) gradually, or would it just set "velocity" to the value of "acceleration" since its a fixed int number?

timber tide
#

acceleration would just be a speed here whoops didn't see you appending to the velocity so this value would be acceleration in this case, though the direction here seems pointless as the initial velocity should be set.

polar acorn
modest dust
#

It can either increase or decrease

#

depending on the forward vector

#

and the acceleration

#

Well, maybe not increase or decrease since it's a vector at the end of the day

#

but it will change, that's for sure

#

Going forward with an acceleration of 1 for 10 seconds will give you something like (10,0,0) velocity

#

but turining completery right will just add speed to your right movement

#

it will still go at the speed of 10 forwards

real vapor
modest dust
#

Well

#

It can certainly work

#

just do mind that the acceleration might skyrocket due to high framerate

#

adding a cooldown to increasing and decreasing the acceleration might be a good idea

real vapor
#

Wouldn't adding "* Time.deltaTime" to "Ahead.z += acceleration" fix that?

modest dust
#

But if you're using delta time then that is just as good I suppose

real vapor
#

Yea.

modest dust
#

But the rate of acceleration change is still higher in higher framerates

timber tide
#

eh it should be constant

modest dust
#

Well, I mean

timber tide
#

probably give an example of what you're trying to do, cause now you have no direction

modest dust
#

If someone were to balance an acceleration of 120 at all times and then stop accelerating

#

at 120fps it would drop to 0 in 1 second

#

at 60fps it would drop in 2 seconds

#

etc

#

could be possibly abused

#

either intentionally or not

real vapor
#

Would that be preventable by adding a cool-down?

modest dust
#

Yeah

#

or by adding a rate of decrease increase per second

#

Ahead.z += accelerationRatePerSecond * Time.deltaTime

#

easier than adding a cooldown

real vapor
#

I see.

timber tide
#

I'm pretty sure that's not necessarily? The idea of delta time is to prevent that exact situation, or maybe I'm not understanding something here.

real vapor
#

Isn't anything that's multiplied by Time.deltaTime frame-rate independent?

modest dust
timber tide
#

Unless you mean instead of using low values of acceleration, you'd make it less frame dependent

modest dust
#

Or unless my brain if fried after 10 hours of work

#

It might actually be alright and I'm just going in the wrong direction

#

Yeah, I think it should be alright.

#

Doesn't matter if the acceleration is 100 or 10000, deltaTime will take care of it

#

My bad.

prime loom
#

Im using this simple script to download jpeg images from a server i have. But Unity sends this errors.

short hazel
prime loom
#

Yeah its a server side issue. I tried with another image from another server and it works just fine.

short hazel
#

If you have Postman or similar you could try querying your API to see what's different with that particular image
Or curl it directly into a file

prime loom
#

Ill check on it. Thanks

quiet dune
#

Is there any way via the Unity editor to show values of fields or invoke methods of scripts without changing the code of the script (like serializing or setting stuff to public)? For ad hoc debugging purposes

summer stump
quiet dune
summer stump
quiet dune
#

Bummer, but thanks 🙂

summer stump
quiet dune
#

Sure. I was hoping for a more convenient and flexible way

eternal needle
#

Although context menu would require you to edit the script to include that line

quiet dune
wintry hull
#

Hi does anyone know how I can get my horror enemy to paterol around a house. Chase you if they see you and play a jumpscare once it get close enough to you

frosty hound
#

Yes, but explaining an entire major feature of a game is not something that can be easily typed. Learn about navmeshes to start.

polar acorn
#

That's like six things, which one are you asking about

summer stump
sour fulcrum
#

Is there an attribute to call [ExecuteInEditMode] on a single function?

#

I found some for runtime but couldn't for editor

teal viper
#

Wdym? When do you want the function to execute?

sour fulcrum
#

Like I want OnEnable to be called in editor but would prefer to have only that function be affected by executeineditmode

#

in the future i'll probably approach it differently just trying to refactor this one step at a time

teal viper
#

I guess there isn't a way to do that for one callback specifically.
But you could make a check in the other functions wether it's edit mode or not and return early if it is.

sour fulcrum
#

yeahhh

#

worst case i can do that

#

I have an enum for it but I think theres a small oversight in unity with prefabs that i gotta watch out for

teal viper
#

Or just use OnValidate maybe?

sour fulcrum
#

nah instansiating gameobjects so no can do unless im mistaken

teal viper
#

You could run the logic from wherever you're instantiating them then.

sour fulcrum
#

I'm instantiating them OnEnable 😛

teal viper
#

Why would you do that?

#

What purpose does it serve?

sour fulcrum
#

Creating/Deleting parent objects for level design based hierchy organisation

teal viper
#

Still don't really get it but ok. Sounds like you want an editor script though.

sour fulcrum
#

Mhmm perhaps

#

I didn't go that way since i didn't think there was any easy awake/onenable things but I guess I can probably do something janky with a bool and onscenegui

timber tide
#
#if UNITY_EDITOR
Func();
#endif```
#

pretty sure the compiler removes it on build

#

at least c++ compilers usually do

frigid fern
#

can someone guide me to getting my ide configuration to work. i followed some tutorials and idk what im doing wrong.

eternal falconBOT
frigid fern
# rich adder !ide

i dont follow. its all installed and i downloaded the game development for unity tab.

#

!ide

eternal falconBOT
frigid fern
#

why is my if statements get replaced with #if?

summer stump
frigid fern
#

well idk why but its not doing it anymore. im really frustrated with this. its not autocorrecting.

teal viper
#

Follow the config guide thtough all the steps.

#

What IDE are you using?

frigid fern
#

idk i just followed some video tutorials and read some stuff on how to do it for visual studios

teal viper
#

Follow the linked guide

#

Are you using VS or VS code?

frigid fern
#

im using vs. and looking at the directions given i have done all of that

sour fulcrum
#

so you/we gotta figure out what step went wrong

teal viper
summer stump
frigid fern
summer stump
#

Ok, that is one step. What else did you do?

frigid fern
#

all of it honestly

#

i just need to find the external tools one sec

teal viper
#

No. It's in unity. It's covered in the guide, so go over it again.

summer stump
frigid fern
#

not to sound rude but i dont see it in the manual that was provided

sour fulcrum
#

its literally the first thing in the unity hub link and very slightly below the start of the visual studio download link

teal viper
#

The manual installation guide

frigid fern
#

oh i did that

#

sorry im super tired

teal viper
#

Well, share a screenshot then

frigid fern
teal viper
#

Okay. Now a screenshot of your IDE window.

#

With any script open

frigid fern
teal viper
#

Assuming that's really the same vs version you have selected in external tools, try regenerating project files.

frigid fern
#

ok i did, nothing really changed

teal viper
#

Another thing to try is to delete the .sln and .csproj files from your project folder and reopen the visual studio.

frigid fern
#

wait, i went to visual editor in unity cause i figured u would have me check it and its locked, it was locked before but i unlocked it and i guess it relocked it. could that be why?

summer stump
#

The Visual Studio Editor package?

#

If so, remove the Engineering feature

frigid fern
#

ok

summer stump
# frigid fern

It shouuuuld be fine with that version, but I dunno.
VS Code needs at least 2.0.20

teal viper
#

Oh, the package. I don't think that matters. Not sure what "locked/unlocked" means but it seems to be installed, so it's fine.

frigid fern
#

oh...does it matter that i already uninstall engineering?

teal viper
#

... Maybe..?

frigid fern
#

i hope not

teal viper
#

Why would you uninstall it?

frigid fern
#

aethenosity said to remove it, so i did. but i reinstalled it. it seems to be a dev thing

#

but going back to ur other suggestion

#

how wouldi go about finding the .sln and .csproj file in my project folder?

summer stump
frigid fern
#

ohhh ok

#

oh wow u were right

#

im bout to see if it works now

queen adder
#

been losing it over trying to find a way to do this:
do any of yall know a way i can rotate an object to be parallel to a collision?

frigid fern
#

it doesnt seem to have

#

done the trick

queen adder
teal viper
frigid fern
#

yes

teal viper
#

Okay. Try right clicking the solution in the solution explorer and reload it.

queen adder
#

currently i've got nothing

#

i've got the rotating down with a quaternion euler thing down

#

but it's just, having it be in relation to the wall is messing with me

teal viper
#

You can use the hit normal to orient your instantiated object.

queen adder
#

cause i want to do it mathematically so it can apply to whatever surfacte it hits

#

mm ill look into that thanks

frigid fern
#

@teal vipersorry for not ussing the reply but i think were getting somewhere. its recognizing the monobehavior but i tried to make an if statement it went to #if again it says snippet, idk if that helps

frigid fern
#

wait

teal viper
#

Of the whole window

frigid fern
#

nvm i thought i had it

teal viper
#

It should show Assembly-CSharp if it's loaded correctly

frigid fern
summer stump
#

This is working

#

You just need to fix the errors

#

semicolon after the basketball line and remove the test if

frigid fern
#

oh. wierd on my other computer it usually gives me the brackets and squiggly lines

#

but if its working ill take it

sour fulcrum
#

it is giving you squiggly lines

summer stump
#

Well... it is showing squiggly lines there. What do you mean brackets?

frigid fern
#

no {} that one

sour fulcrum
#

ifs dont use that

teal viper
summer stump
teal viper
#

It would only give you suggestions if they are correct in the context.

frigid fern
#

right

#

oh

#

see i wish i had my old computer it went out. and i had to get the other one. on that one it autofilled itself

#

or was that an add on or something like that

sour fulcrum
#

its not going to auto fill if it's not a valid place to use that

summer stump
#

you can't just put an if where you have it. That is not allowed in c#

frigid fern
#

well an ex say i started with if.. it would the add () {} without having to type it

#

it was incredibly useful

summer stump
#

Did you try in a method like we said?
You have it OUTSIDE any method right now, as of the last screenshot

frigid fern
#

yeah its in the method its doesnt really do it like that tho

sour fulcrum
#

Screenshot?

summer stump
frigid fern
#

well... yeah u told me to

teal viper
#

If I TAB here

#

It autocompletes to

#

Is that what you mean?

summer stump
frigid fern
# teal viper If I TAB here

not really the if statement would fill similar to that but you wouldnt have to put anything in it would just auto fill () and{ } like so

frigid fern
#

it would show before pressing tab as well

frigid fern
#

im typing if and pressing tab and only getting if

teal viper
#

tab twice

#

It even says that

frigid fern
#

yeah i never had to press tab twice before

#

and true was never in it either

teal viper
#

Then you have some custom settings for all we know🤷‍♂️

frigid fern
#

got you

teal viper
#

You'd obviously need to type in your desired condition

summer stump
#

It even autoselects true so when you type it removes it

queen adder
frigid fern
#

i done it with a guy in the discord and the way he instructed me was how i got it

queen adder
#

probably should specify that i'm working in 2d ofc 😅

teal viper
frigid fern
#

its fine if it is custom ill figure it out.thanks for helping out as much as u did

teal viper
queen adder
#

AHHHH

#

forgot about the transform jank

#

thank you 👍

spring coral
#

quick question, im having a weird issue with instantiating a canvas, then immediately updating its values:

#

something like this pretty much, but this is producing some weird results

#

sometimes the overrideSorting or sortingOrder is unchanged

#

example 1 (where override sorting is not enabled, but the sorting order is properly changed to 3)

#

ok actually, figured out something weird?

#

if the parent canvas isnt enabled the frame i try this instantiation then it exhibits the weird behaviour

#

switching the override sorting/sorting order seems to half fix it

#

yeah, this weird issue got fixed by delaying the instantiation a frame later so that i can let the parent canvas enable, weird

hallow badger
#

Is best way to learn code make all code by yourself of just look at some assets that are make it your one?

cosmic dagger
#

and always go over the basics: type, reference type, value type, primitive (built-in) types, class, struct, interface, an instance, variables, methods, events, OOP, encapsulation, etc . . .

olive lintel
#

hi guys, how would I go about making a function that has "overloads", like optional arguments that I don't necessarily need to type in to use the function (as they aren't always necessarry). The one in my case specifically sometimes requires the use of a scriptable object

cosmic dagger
eternal needle
brazen canyon
#

Excuse me. I need a little help with my Animation

#

Why does it play and stop play and stop like this ? T-T

olive lintel