#💻┃code-beginner

1 messages · Page 213 of 1

teal viper
#

You can also right-click it and there would be options to go to definition and initialization.

#

Yeah, I think that's correct.

sour fulcrum
#

I feel like there must be a reason for that i'm missing

teal viper
#

And overall, unity tags are somewhat useless.

#

You'd usually have your own mechanism of object identification.

polar acorn
#

Just make a script with a string property or even a list of strings, use those to identify objects

sour fulcrum
#

That's fair. My usecase is in a modding scenario so i totally get that nothing is inherently designed to support that but man it's not a fun hard limitation to run into aha

#

Looks like the related functions and properties are handled on the c++ side of things so i'm guessing maybe hardcoding it helps for performance while using findobjectbytag and such

verbal dome
#

target is a property in Editor class which your custom editor inherit from

#

It's just the object the editor was made for

sour dome
#

It looks like Unity doesn't like line 10, I know the RunProceduralGeneration works so that's not the problem. This is the warning in Unity You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all

frigid sequoia
#

I have a particle system that sends waves progressively faster to warn that an enemy is about to explode, when adding sounds, there is a way of making it in sync with the particles or do I have to do it manually?

slender nymph
sour dome
sour dome
slender nymph
#

which means AbstractDungeonGenerator inherits from MonoBehaviour

slender nymph
#

why

sour dome
# slender nymph why

no idea, I'm just trying to understand how this is working, got it from a youtube video

slender nymph
#

if you do not need any of the messages like Awake, Start, Update, etc and you do not need to attach it to any object as a component and would rather construct it using the new operator, then do not inherit from MonoBehaviour

sour dome
#

I know that this button in the editor is working with this code, but not sure how.

sour dome
#

in the editor's script

slender nymph
#

if you need this to be a MonoBehaviour, such as for attaching it to a gameobject like you are in the screenshot above, then do not instantiate it using the new operator

verbal dome
slender nymph
sour dome
#

omg! that works great, I just exposed it using [SerializeField] and then reference it!

stone elk
#

is there a way to hide a game object without disabling its scripts?

stone elk
#

2d

broken trellis
#

Layers

summer stump
stone elk
#

let me ask a different question: is there a way to enable or disable a script through script? if that makes sense

#

i think that will be better for me

summer stump
#

Only scripts with unity methods can be enabled though (or at least react to it)

stone elk
#

ok thanks'

summer stump
#

Only Update and stuff like that will be disabled

#

All other code will continue to run if called

#

Oh, that was correct doot. .enabled = false

broken trellis
#

gameObject.GetComponent<EmailSender >().enabled = false;

#

Hey, I'm trying to make a snap grid controlled by mouse for a battlefield TCG I'm designing. I can't get the grid to actually snap the object though.

#

When I move my object on the board, it doesn't snap

#

Also yes, I used GPT and modded what was needed, but I hit a stone wall.

small mantle
#

I need help finding a Beginners course on AI on Unity Learn. Preferably 2D

teal viper
#

Also !code

eternal falconBOT
broken trellis
teal viper
nocturne parcel
#

What is the transform parameter in the TileChangeData constructor?

#

The documentation is too vague

small mantle
sour dome
#

I have these spawn points but I can't seem to drag them into my List<Vector2Int> serializedfield, am I supposed to be using List<GameObject> instead?

rich adder
teal viper
nocturne parcel
#

But there is already a Vector3Int position parameter...?

teal viper
nocturne parcel
teal viper
rich adder
small mantle
teal viper
rich adder
small mantle
summer stump
teal viper
# nocturne parcel thank you

What you're probably looking for is a behaviour for computer controlled characters, which in itself is already a very ambiguous thing. For example, ai in a 2d platformer would be very different than a simulator, like Sims or something.

nocturne parcel
#

Wrong ping

sour dome
#

somehow I am getting index was out of range error, am I missing something here?

teal viper
sour dome
#

I have 2 chickens (same prefabs)

teal viper
#

We don't know if that screenshot corresponds to what happens in reality.

rich adder
#

also make sure you dont have a copy of this script somewhere with missing elements..

queen adder
#

How do you get references, tips, whatever you call it in visual studio?

eternal falconBOT
queen adder
# rich adder !ide

I’m assuming that’s a commonly asked question if there’s a command for it

rich adder
#

indeed 🙂

stone elk
#

how come my play button isnt clickable until i disable my floating joystick?

rich adder
#

probably covering it

cosmic dagger
#

is it blocking the play button??

stone elk
#

not really

rich adder
#

how do you know

#

did you debug it

cosmic dagger
#

that's not definitive enough. check if it is or is not . . .

rich adder
#

Inspect the Event System gameobject during playmode and find out

sour dome
#

so line 28 should generate a newEnemy gameobject as a child of whichever gameobject is holding this script right?

gaunt ice
#

No

cosmic dagger
#

Nope . . .

slender nymph
#

it instantiates it as a child of spawnPoints[randPosition]

timber tide
#

you can hover over the method implementation for a hint at the parameters

cosmic dagger
#

Wait, is spawnPoints[randPosition] a transform?

timber tide
#

and if you do the secret visual studio hotkey handshake you can pullup a list of overloads inside of visual studios itself!

stone elk
#

i checked the event system. nothing changed

cosmic dagger
# sour dome yes

Then you need to use the transform of this GameObject (the script is on) . . .

stone elk
#

but when i disable the joystick, my play button slightly changed colour

rich adder
#

while hovering the button you cannot click in playmode, screenshot the event system in inspector

broken trellis
#

I made some mods to it, but it still isn't wanting to snap

stone elk
sour dome
#

Weird, it seems debug on line 21 is running just fine with results, but line 22 is not running because the Debug.Log() in 27 is not firing. What am I not seeing here?

rich adder
#

even the IDE is suggesting the fix..

#

the 3 dots, pay attention to them

sour dome
slender nymph
sour dome
#

wait a minute, if I'm reading this correctly, FixedUpdate() is running every seconds so I'm generating a new Coroutine per second that repeats per interval right? so it'll grow exponentially?

gaunt ice
#

What repeat?

eternal needle
#

You are just starting a coroutine every fixed update, that is all

gaunt ice
#

But you are creating around 50 new coroutines per second

slender nymph
#

yeah by default FixedUpdate runs 50 times per second, not once per second

stone elk
#

@rich adder im trying to send my video but the file is too big

rich adder
stone elk
#

ok

#

play and shop button doesnt work

#

but the others do

rich adder
#

no shit, look how big the rect transfrom for the floating joystick is

stone elk
#

yeah but im not sure if thats the issue

rich adder
#

hey remember this..

#

Not really... whole fucking rect transform is over it

stone elk
#

i made it bigger and the other buttons worked fine

rich adder
#

fix the sizing of the rect

stone elk
#

but i want the floating joystick to be used anywhere on the screen

rich adder
#

clearly have a pretty big misunderstand how the UI works in unity

#

as this is not code related

stone elk
#

yeah i am beginner

#

ok thanks

rich adder
#

well step 1 dont cover other UI elements you wish to click on with another UI element's rect transform

hybrid gust
#

Alright I'm stumped.
Still working on this for 2 days and I think I'm overcomplicathing this.
All I want is for the mouse to move a 3D object (not on screen) to between these points, im not sure what the best way to do that would be.
My first instinct would have been to just do a raycast for these positions and tie some coliders to em. But then I run into the issue where the player has to find the EXACT spot the collider is at, and the collider isn't really 1 to 1 with the visuals.

My OTHER idea was to have the player "drag" that 3d object around and have the 3d object snap to the nearest valid position. Which I think would work better, but I'm not sure how to go about implementing that. I've throught about turning all these points into screen space and handling that way, which I already have the logic to do, for the most part. But I'm not sure how to do the logic for the snapping or dragging of the 3d object TO those points. Someone have any suggestions or a resource or something?

rich adder
#

with your second idea

hybrid gust
#

Physics overlap?

rich adder
#

actually why not store those inside an array of positions and maybe check the 3D object which one is closest distance and just snap to it

hybrid gust
#

Well that the thing, the dragging part is where I'm stumped

#

the most^

rich adder
#

in what sense?

hybrid gust
#

Like, how do I turn the mouseInput into a 3D vector that returns the closest point?

#

Or correction

#

MouseInput into the snapPoint

rich adder
#

You want that done after the placement right?

hybrid gust
#

Here is a better visual

#

That cube

rich adder
#

make object follow cursor with a ViewToRay

hybrid gust
#

I need the mouse to move that cube to those point based on where the mouse is on screen

#

ooooh

rich adder
#

then snap the object on the board, on mouse release or whatever snap to one of the pos

hybrid gust
#

view or camera?

rich adder
#

put a simple flat collider on the top of the board for easy "surface snapping"

hybrid gust
#

So 2D collider above the board. Find the nearest point from the hit location. Snap the Cube to that point?

rich adder
#

yeah something like that except is this not a 3D game?

#

use 3D colliders

hybrid gust
#

it is

#

OH I was just going to make it 2D cause this would be a fixed camera angle

#

Not to mention I wouldn't want the player to be able to hit the collider from the side

#

I guess technically speaking it would still work the same

rich adder
#

you're only hitting the face of the cube collider

#

you cannot hit the other side

hybrid gust
#

Well I meant the side faces not the bottom face

#

but either way It doesn't make a difference, if anything, you're right a cube would probably work better if I didnt' want the fixed camera angle

#

Cause at the end of the day, the cube would still just snap to the closest point

rich adder
#

the purpose of the collider is to detect the board's surface

#

since its on a tilt

hybrid gust
#

right

sour dome
#

There seems to be a lot of ways to spawn enemies based on a timer. Obviously there are pros and cons for each method, is there a concensus to which is decent to use for a first project? I'm leaning toward InvokeRepeating in Start()

rich adder
glad quiver
#

Anyone know if there is a way to display a variable in the inspector if the variable exists only in a state script? The state script doesn’t attach to anything, only the state manager does, so it’s not letting me use public/serialize field to display the variable I want.

teal viper
cosmic dagger
cosmic dagger
glad quiver
#

You can serialize the state script itself? 😮

#

I had no idea (messing around with state machines for the first time ever)

cosmic dagger
#

You have to serialize C# classes/structs to appear from the inspector. It's nothing to do with a state itself . . .

rich adder
glad quiver
#

I see, thank you. Normal default classes I’ve used all allowed that automatically so I didn’t know!

glad quiver
rich adder
#

ahh ok

cosmic dagger
sour dome
#

what's the recommended way to store global variables like a kill counter across the whole game? I'm thinking of adding it to the menu gameobject and pass it as a reference to the bullet script so that it can increment upon collision - is that a bad idea?

rich adder
cosmic dagger
sour dome
cosmic dagger
#

You mentioned a menu GameObject, so we figured it was connected with a UI . . .

sour dome
#

ah I see

glad quiver
#

Maybe I’m misunderstanding then. My state script doesn’t use monobehavior, and it doesn’t attach to a game object. The state manager script attaches to the game object and that script uses the state script.

rich adder
sour dome
rich adder
#

keep track of it in a stats manager or something

glad quiver
sour dome
cosmic dagger
rich adder
cosmic dagger
sour dome
rich adder
#

learn actual c# events

cosmic dagger
next hull
#

private void RegisterNetworkObjects(NetworkRunner runner) => runner.RegisterSceneObjects(networkObjectArray);

error CS7036: There is no argument given that corresponds to the required formal parameter 'objects' of 'NetworkRunner.RegisterSceneObjects(SceneRef, NetworkObject[], NetworkSceneLoadId)'

How to Solve It!!

cosmic dagger
craggy oxide
#

finished my junior programming course 🥳

#

now i guess it's onto the creative core stuff

#

honestly i feel like the junior programmer stuff is missing a lot, there wasn't anything about raycasts which are pretty essential

rich adder
craggy oxide
#

bro-

#

bro i'm not asking for a raycast tutorial

#

i'm just saying it wasn't included in the junior programmer course, which covers a lot of bases otherwise

#

fr hittin me with the nerd emoji rn

cosmic dagger
cosmic dagger
summer stump
native seal
#

is there an issue with the way im intializing my array? it seems to be causing issues

gaunt ice
#

So what is the problem

native seal
#

the slots are sometimes turning to null

gaunt ice
#

Your inventory is public so everyone can modify it

native seal
#

i know, thats not the issue, im specifically asking about the way I initialize it

gaunt ice
#

It should work

#

Everyone initialize their array this way

native seal
#

okay thanks

teal viper
#

Not sure what that event(?) with raise and null parameter is about though.

native seal
#

its my own event system

#

it doesn't need to be null, just forgot to remove the ?

teal viper
#

I mean, the fact that you're invoking it with null as parameter is a bit sus.

native seal
#

I don't need to be

gaunt ice
#

Parameter not the conditional checking

teal viper
#

The ? and the null parameter are 2 separate things, so I'm not sure I understand what you're trying to say.

native seal
#

ah

#

its the way I do null events

#

void events*

#

you have to pass null

teal viper
#

What's even a null event? The end of the world or something?😅

native seal
#

void events*

teal viper
#

Aah, I see. Weird, but ok.

native seal
#

it works great

charred spoke
#

Fuck is a void event

eternal needle
#

i was questioning if i was just dumb and didnt learn something about events 😅

native seal
#

an event that doesnt send any data

#

i have int events and other custom data types that can be sent through events

#

easy way to connect logic and UI

#

for example when I swap an item in the UI, it just sends an event with the two indexes in the inventory and the logic swaps the items then updates the UI

teal viper
eternal needle
charred spoke
#

Or Metro

#

Wait metro does not have anomalies

teal viper
#

I was thinking Warhammer

native seal
#

its just an empty class

#

to send no data

eternal needle
#

🤔 just dont use a type then

#

this is pointless

charred spoke
native seal
#

for the way I do it, you have to specifiy a type

teal viper
#

Void class is creating some cognitive dissonance 😅

native seal
#

nah the way I do it works well

eternal needle
#

honestly that was the LAST thing i was expecting

native seal
#

its just for the events

summer stump
#

This is cursed

native seal
charred spoke
#

My brain feels like it is getting a void event right now

native seal
#

i have to specifiy a type on the listener

#

therefore, if I dont want to send data, i use a "void" event

eternal needle
#

this looks awful

native seal
#

ok bro

#

thanks

teal viper
#

But seriously, it kinda wraps unity event without providing any benefit. What's the point?

charred spoke
native seal
#

read, thanks

#

i just adapted that

teal viper
#

But, it's not an SO🤔

eternal needle
#

what you've shown is completely different to what you have

summer stump
#

Adapted to the point it is unrecognizeable

teal viper
#

Or are the events themselves SO?

native seal
#

yes

teal viper
#

I see

native seal
#

I can just plug these in to anything to and hook a function up using unity events

charred spoke
native seal
charred spoke
#

Like let me tell you. I run a studio. If I get to see a system like that in your portfolio when you apply for a job I am immediately tossing your application in the garbage

#

And usually I am a very good and tolerant person. That is how bad this system is.

native seal
#

it works perfectly, is modular, and is very simple to follow

#

i dont see the issue

#

i dont think you understand the full system

eternal needle
#

a lot of things "work perfectly" aka do what they are intended to do. I could say the same about using the Find functions, or stuff like SendMessage

#

you having to declare that Void class should already be a red alert, that this infact is not working perfectly. All of us were even shocked to have seen it.
Imagine how someone who has to work with you would react

native seal
#

i disagree man, the void class could have easily have been called NoData or something similar

eternal needle
#

so? the name is irrelevant. you are declaring a class with nothing in it. this is what i would call jumping through hoops to make a system work

#

you could name it OogaBooga for all i cared

native seal
#

it is not jumping through hoops though

#

it just an event passing no data

#

somewhat of an edge case you could say

eternal needle
#

you know what else passes no data? Action

gaunt ice
#

I think the listeners won’t expect their publisher passing a null to them….
Imagine you receive a package and open it, nothing

noble summit
#

is everything that you need to develop in unity learnable in unity learn/docs

eternal needle
#

i can see cases where it makes sense that the data could be null, but yea intentionally passing null is just weird.

native seal
#

it is because raise needs a type

static bay
eternal needle
native seal
static bay
#

you dont

#

you can have Action which takes no parameters

#

and then Action<T> which can take one parameter

#

and I think there's ``Action<T,...>` up to like 16 arguments.

eternal needle
static bay
#

And there's UnityEvents that follow that same structure.

#

Oh

native seal
#

i just asked a question about an array and got chewed out for the way i do events

#

lmao

eternal needle
native seal
#

yes but using just using base c# events does not allow for that

#

i understand an event bus is different but I don't want to implement that as I don't fully understand it

#

my system works just as well and accomplishes the same thing

static bay
#

I like the sound of UnityEvents living on ScriptableObjects. Give them a subscribe/unsubscribe and publish method.

#

Pretty good way of having a designer friendly event system.

native seal
#

that's exactly what I do

static bay
#

I think you have Monobehaviours marked as listeners though

native seal
#

yes, i guess you could say that's a limitation

static bay
#

Only one event, right?

native seal
#

no the downside is that you need to have a listener on the gameobject to respond to events

#

so my system only works with monobehaviours and other SOs

#

base c# classes can't recieve events

#

but so far I have had no cases where I need that so

#

for example,

teal viper
# native seal

You could implement an overload of Rise that doesn't take a type.

native seal
#

sure

#

doesn't change much though

#

imo its simpler to just write null

static bay
#

You see the real big dick play would be doing...

public class Void
{
    public static Void Instance {get;} = new();
}

and then passing

Void.Instance
native seal
#

these guys in here would love it

eternal needle
# native seal these guys in here would love it

🤷‍♂️ its not like it affects us or anyone that commented truly cares. we are just pointing out what we consider to be flaws. Basically as Uri said, if you show this system on a portfolio, you will get a few raised eyebrows

native seal
static bay
#

I think it's just that passing null as a parameter is usually seen as... odd. Functions usually expect to be given things to work with.

native seal
#

yes I could easily make a overload with no parameters

#

just never did it since it works fine

burnt vapor
wooden minnow
#

where do i ask for help about unity inspector things?

burnt vapor
grand swan
#

can someone look at my code and give me guidance on making it easier to read and manage. its my character controller script and it contains 3 main section: detect objects, go to target, look at target. i feel like it shouldn't be more than a few hundred lines of code. but instead its over 2,000 lines of code.

iv been working on it for a few months on and off and its getting bigger each time, and im not sure how to restructure it. im thinking of trying to splits each section into their own script. and then maybe split those into smaller scripts. but im not sure how im going to go about that as i am a beginner level 'coder'.

hidden sleet
#

I've heard about 'dependency injection' a couple times recently, is that essentially the act of setting the value of a field through the inspector?

rare basin
#

no

#

read about Zenject

burnt vapor
#

It's more useful in non-Unity .NET applications, really. Especially because Unity doesn't have proper support out of the box

hidden sleet
#

Is that why there tends to be third party tools for that?

upper night
#

Hey Peeps,

kinda riping my hairout writing a script to control animations i have this block of code

        {
            animator.SetTrigger("pop");
        }```

its in the update function, but the animation dosnt change

however manually setting the trigger in the editor changes the animation is my code wrong?

objecty is set to postion Y in the above line
burnt vapor
#

In Unity you have various different ways of creating and disposing dependencies

#

If you register one, should it exist until scene change maybe, or should it be disposed when something else happends?

#

I think stuff like this is left to libraries due to how much can be configured

#

Either way, you can just write your own, because it's not a complex system to do (unless you're a beginner ofc)

hidden sleet
#

I see

burnt vapor
#

But it's probably also because DI usually works with constructors and Unity doesn't use those

hidden sleet
#

as i'm still a rookie, is it something worth putting some time into studying or could it mostly just be another approach I could bear in mind?

burnt vapor
#

Dependency Injection as a whole is important to understand, even if you never use it in Unity

#

It's a general term used by a lot of languages and frameworks

hidden sleet
#

In that case I'll give it a further look later on

mossy sphinx
#

i am making a grapple hook and im using line renderer as my rope. I want to make it so that the line renderer doesnt just pop up and dissaperas, i want it to look like i shoot the rope from the guntip to the grapple point.
the code is in the link, thank you.
https://hatebin.com/ewzctdqrwm

upper night
#

anyone any idea why

    {
        ChangeAnimation();
    }

    void ChangeAnimation()
    {
        // Get the object's current Y position
        float objectY = transform.position.y;

        // Check the object's Y position and play the corresponding animation
        if (objectY > 0f)
        {
            animator.SetTrigger("pop");
        }
        
        
    }``` dosnt work?
languid spire
upper night
#

@languid spire massive derp moment 2 hours trying to figure it out, didnt actally attach the script works flawlessly fml ty!

languid spire
#

occam's razor

shrewd saddle
#
PlayerInput+WalkActions.Get () (at Assets/Scripts/InputSystem/PlayerInput.cs:194)
PlayerInput+WalkActions.Enable () (at Assets/Scripts/InputSystem/PlayerInput.cs:195)
InputManager.OnEnable () (at Assets/Scripts/InputManager.cs:33)```
anyone know how to fix this error?

```public InputActionMap Get() { return m_Wrapper.m_Walk; }
public void Enable() { Get().Enable(); }```
line 194+195 ^ 

```WalkMovement.Enable();```
line 33 ^
verbal dome
burnt vapor
#

If it's a component, be sure to add it

#

Otherwise please share all the !code

eternal falconBOT
verbal dome
#

@upper night Or what is this line doing? cs grapplePoint = Vector3.Lerp(grapplePoint, swingPoint, t);

shrewd saddle
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class InputManager : MonoBehaviour
{
    private PlayerInput playerInput;
    public PlayerInput.WalkActions WalkMovement;

    private PlayerMotor motor;
    private PlayerLook look;
    // Start is called before the first frame update
    void Start()
    {
        playerInput = new PlayerInput();
        WalkMovement = playerInput.Walk;
        motor = GetComponent<PlayerMotor>();
        look = GetComponent<PlayerLook>();
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        motor.ProcessMove(WalkMovement.Movement.ReadValue<Vector2>());
    }
    private void LateUpdate()
    {
        look.ProcessLook(WalkMovement.PlayerLook.ReadValue<Vector2>());
    }
    private void OnEnable()
    {
        WalkMovement.Enable();
    }
    private void OnDisable()
    {
        WalkMovement.Disable();
    }
}
upper night
#

@verbal dome idk thats no my code

shrewd saddle
#

it shouldnt be empty

#

or null

burnt vapor
verbal dome
#

Oh sorry

#

I pinged the wrong guy lol my bad

burnt vapor
#

Perhaps it's fetched too late

shrewd saddle
verbal dome
grizzled surge
#

Yo I got a question, I am trying to make a gameover screen with the buttons "Restart" and "Menu" and a start screen with the buttons "PLAY" and "QUIT" I can't seem to find a good way to make the player get sent back to menu from the gameover screen

#

Could someone help me?

verbal dome
#

@mossy sphinx Your lerp seems incorrect. You are doing this current = lerp(current, end, t)
When you should do something like current = lerp(start, end, t);

#

(Pseudo code)

keen dew
#

You'll have to give lot more details than that

grizzled surge
#

The script I use for going between different menu is just loading different scenes

#

but after loading "game" scene again it doesn't let me move my car

keen dew
#

That sounds like a different problem but ok

#

Do you set the timescale to 0 in the menu?

grizzled surge
#

this is the menu script

solid sail
#

For performance reason, I should try not return array of function as possible? Maybe I remember wrong?

#

But what if I just want to have a function to return array of bytes?

grizzled surge
verbal dome
#

And maybe return an integer too that stores the count of valid items

grizzled surge
kindred halo
#

I have a component that follows another objects rotation and moves accordingly
when I play it jitters
but when deactivate the component while playing and activate it again it doesn't jitters anymore
I used late update
but that just makes the jitter constant

solid sail
verbal dome
#

Passing it into a function doesn't copy it

grizzled surge
#

So another problem: My score keeps counting after gameover, what should I add to stop it?

solid sail
#

Ohhh.Yes! That's true!

mossy sphinx
languid spire
mossy sphinx
burnt vapor
eternal falconBOT
kindred halo
kindred halo
languid spire
#

opening a box with the knife which is inside the box?

kindred halo
languid spire
#

yes

calm hull
#

hello, one question. Im new in this
I created a canvas for a menu and added a image on it. Now im trying to add a button on one of the options so when clicked it moves to the next scene. However the OnClick() dont show the functions of the script so im not sure how to di it

#

they are public so thats not the problem

ivory bobcat
#

Did you reference an instance in the scene or the asset?

burnt vapor
calm hull
#

how can i paste code here?

ivory bobcat
#

!code

eternal falconBOT
burnt vapor
#

You can paste !code using a site or directly

eternal falconBOT
calm hull
#
// Your code here
using UnityEngine;
using UnityEngine.SceneManagement;

public class CambioDeEscena : MonoBehaviour
{
    string nombreDeEscena;
    // Método público que cambiará la escena
    public void CambiarEscena(string nombreDeEscena)
    {
        SceneManager.LoadScene(nombreDeEscena);
    }
    public void Prueba()
    {
        SceneManager.LoadScene(nombreDeEscena);
    }
}

#

i did 2 to try

#

none of them appear

#

this right?

hexed terrace
calm hull
#

when i click it it puts that

#

change names for some reason

hexed terrace
#

the file name and the class name need to be the same, so either you've got the file name wrong, or selected the wrong thing

#

and you should be dragging it in from a gameobject, not the project window

languid spire
calm hull
#

so i dont have to drag the script?

ivory bobcat
calm hull
#

the button?

ivory bobcat
#

The game object with the component script you're wanting to access

hexed terrace
languid spire
rare basin
calm hull
#

oh so i need to attach the code to the button and then drag the button to OnClick()?

burnt vapor
#

To be fair, even if class and file name could differ it's very confusing and bad practice in general

#

So just make sure it's the same to avoid confusion

rare basin
#

sure, that wasn't my point ;p

modern rover
#

when i clear the resolved libraries in unity the aab building is perfectly fine but after resolving libraries the .aab not building perfectly

hexed terrace
# rare basin sure, that wasn't my point ;p

your point is currently not really relevant, the amount of versions that allow you to have different names is so low it's easier to just carry on saying the names need to be the same ¯_(ツ)_/¯

calm hull
#

why they are different? i never named it like in the Inspector

rare basin
#

since i said that

calm hull
#

ignore my super drawings

#

xD

rare basin
#

that they dont need to match, no drama lol

#

so yes it is relevant, cause if they are using newer unity versions, what you said is not correct

burnt vapor
rare basin
#

but ofc it's good to always have same file and class name

calm hull
#

i had to right click and hit reset

#

not it changed name

#

to the same

#

strange

hexed terrace
rare basin
#

@calm hull is your IDE configured?

calm hull
#

you mean visual?

#

i didnt configured anything

rare basin
#

i mean whatever IDE you're using

hexed terrace
#

!vs

eternal falconBOT
#
Visual Studio guide

If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:

Visual Studio (Installed via Unity Hub)
Visual Studio (Installed manually)

calm hull
#

let me check thanks

cosmic dagger
rare basin
calm hull
#

yea dont show errors ill fix that

#

cant you fix it without reinstall?

hexed terrace
#

yes, no need to re-install

calm hull
#

oh i see i never programmed in cs

#

only c++

#

lol

#

need everything

#

yesss

#

works now

#

thanks guys!

#

i was using the script and not the button in the gameobject

brazen canyon
#

Hey guys, is this the right way to declare a TextMeshPro ?

brazen canyon
hexed terrace
#

TMP_Text is best to use

brazen canyon
cosmic dagger
hexed terrace
#

Why would the syntax differ? 🤔

calm hull
#

other question, imagine a want to do a rpg turn game, where you have 4 characters. Im trying to do the campaign with 10 levels each level different scenery and different enemies. Should i do a general combat scene and depending on the level code the variants of i should maek one scene per level?

rare basin
#

i'd go with one scene loading proper data for that level from scriptable object for example

#

imagine having 100 levels

calm hull
#

i see

#

okey thank you

verbal dome
brazen canyon
#

Hey, i wanna run the array from the first element to the last element and then return to the first element

#

How to do this ?

languid spire
brazen canyon
rare basin
#

don't be childlish please

brazen canyon
#

I just don't rememer how to call it right now

#

Oh yeah

#

Elements

rare basin
#

probably loop

#

through the array

brazen canyon
rare basin
#

but why do you need to loop

brazen canyon
#

Silly me

rare basin
#

if you want to return the first element anyway

#

array[0]

brazen canyon
#

for (int i = 0; i < n.length; i++) {
show(array[i]);
if(i == n.length) {
i = 0;
}
}Like this ?

rich adder
#

what are you trying to do exactly

rich adder
languid spire
rare basin
#

nvm if(i == n.length)

languid spire
#
while (condition) for () { }
rare basin
#

that's never true

rich adder
brazen canyon
burnt vapor
brazen canyon
#

Like a ring you know ?

burnt vapor
rare basin
#

🙂

rich adder
#

you probbaly want to wrap it with %

burnt vapor
brazen canyon
burnt vapor
#

It sounds like you want virtual scrolling

rich adder
#

currentIndex = (currentIndex + 1) % array.Length;
if you want wrap backwards its :
currentIndex = (currentIndex - 1 + array.Length) % array.Length;

#

this will "warp" back to first item

rare basin
#

whats wrong with you and that emojis

#

cringe

burnt vapor
#

Coding is scary

brazen canyon
verbal dome
#

It's kinda spammy tbh

rare basin
#

it's spammy and annoying

#

and chidlish

brazen canyon
#

Ok sorry, I'll control it

final kestrel
#

Is subscribing to events on update bad practice?

rare basin
#

yes

#

why would you do that

final kestrel
#

I have this EnemyAI script which sets the _isProvoked. I also have another script attached to enemy that handles the damage take. I fire off an event on damage take and subscribe to it on my EnemyAI. I did not know where else I could do that and put it in update. https://hatebin.com/ugwqtwfapo

rich adder
#

you only need to sub to events once, no need for multiple frames to do it UnityChanThink

final kestrel
#

I am just trying to learn how events work so yeah

rich adder
#

tie an actual function instead of using anonym imo

burnt vapor
#

Nothing like learning by breaking your editor

final kestrel
#

I can do an actual function yes

cursive thicket
#

how can i get rid of this?

languid spire
rich adder
burnt vapor
cursive thicket
#

ok

#

ty

final kestrel
#

how does OnEnable and OnDisable work here?

#

I mean enable and disable what

rare basin
#

google

verbal dome
#

Did you check the docs for those?

final kestrel
#

I should do that. Thanks for the answers.

brave compass
rich adder
#

good point

final kestrel
#

Ahh

#

Okay wow thats all good now. Thanks again.

#

I cannot unsubscribe if I use anonymous methods right? or am i missing something

burnt vapor
#

Nope

#

It works by reference and anonymous stuff has none unless you store it in a variable

#

It's generally better to just write a method for it

final kestrel
#

Makes sense. Thanks

sour dome
#

In javascript, I usually do console.log([object1, object2]) is there something similar in unity/c#? I'm aware of Debug.Log() but it seems a bit limited to just string (or maybe I'm just using it wrong?)

rich adder
#

using it wrong

cosmic dagger
sour dome
# rich adder

ah ok, but I can't do Debug.Log([object1, object2]) right? because that would be GameObject[] instead of a singular object?

rich adder
#

array is still an object
it wont print the elements but the array itself

cosmic dagger
sour dome
#

I was trying to debug line 21, figured I was going to do 1 Debug.Log() for both portal and gameObject for convenience

rich adder
rare basin
rich adder
#

you're in a type-safety language, use it to your advantage

cosmic dagger
sour dome
modest dust
#

You can just do

Debug.Log($"Portal: {portal.gameObject.name} | This: {gameObject.name}");

And use .CompareTag() instead of names. (or components as Xaxup said)

rare basin
#

components give you more control over tags

#

TryGetComponent and you have reference to the instance already

#

with tags you need to compare, then get the component

#

gets messy

rich adder
#

yeah who wants to sit there make a new tag each time

rare basin
#

i very rarely use tags

burnt vapor
#

String comparison will always be slow though, even with these changes

rare basin
#

whatever you want

grizzled surge
#

What have I done wrong?

rare basin
#
if(collider.TryGetComponent(out Player player))
{
   Debug.Log("collider has Player component");
}
hexed terrace
cosmic dagger
rare basin
#

and you can acess instance of that player

#

player.healthSystem etc

grizzled surge
rare basin
#

chill man

cosmic dagger
rare basin
#

you are missing a bracket probably

#

is your IDE configured

languid spire
eternal falconBOT
hexed terrace
cosmic dagger
# grizzled surge What have I done wrong?

also, post the entire class as the snippet doesn't help because there isn't enough information. make sure your IDE is configured; you should see red squiggly lines in your code. you have fields or methods located in the namespace —outside of the class . . .

rare basin
#

it is not configured

burnt vapor
eternal falconBOT
burnt vapor
#

After that the error is clear

sour dome
#

so the type for the TryGetComponent would be the component's name? in this case would be PlayerController right?

burnt vapor
#

Component = class

cosmic dagger
#

only Components can attach to GameObjects . . .

sour dome
#

ah nice! I got it working with components Debug.Log($"IsPlayer: {collider.gameObject.TryGetComponent(out PlayerController _) }");
thank you!

burnt vapor
sour dome
burnt vapor
#

Guess not

#

Discard properties are there to discard variables

shell sorrel
burnt vapor
#

Not sure why the type is needed here

shell sorrel
#

also it needs the type because its a generic method

#

so you need to provide the type on the out, or provide it after the method name in the <T> area

burnt vapor
#

Ohhhhh he doesn't have the generic type parameter

#

Right, add that and then it's not required

shell sorrel
#

it can infer the generic paramater if there is a type in the args

cosmic dagger
#

if you use TryGetComponent<PlayerController> it should work . . .

shell sorrel
#

but no type from _

burnt vapor
#

I'm blind

rare basin
#

in the debug log he is not, but you dont see other part of the screenshot

burnt vapor
#

Good job team

sour dome
#

but that just move the text from () to <> lol

rich adder
rare basin
#

yea cache it

sour dome
#

so that?

rich adder
#

lol why _

cosmic dagger
# sour dome so that?

but TryGetComponent is unnecessary for a log. instead, use it if you were using the variable . . .

rich adder
#

also no you still wrote it TryGet twice

shell sorrel
#

they mean cache the return of it

burnt vapor
# sour dome so that?

You might as well store the boolean call in a variable if you were to call TryGetComponent twice

rare basin
#

what TryGetComponent does

burnt vapor
#

Does Unity not have a ComponentExists method?

rare basin
#

and whats out parameter

#

do you?

#

@sour dome

sour dome
#

ah I think ya'll meant to cache the result of TryGetComponent and use that instead?

rare basin
#

you dont need TryGetComponent

#

if you dont use the out result

shell sorrel
#

well looks like he is using a component as a tag

#

so might not need the data in the component but needs to know if it exists or not

rare basin
#
bool IsPlayer = collider.gameObject.GetComponent<PlayerController>() != null;
rich adder
rare basin
shell sorrel
rich adder
#

i know Im saying if they need the component

rare basin
#

yup

rare basin
shell sorrel
#

also if just discarding you can declare it in line

shell sorrel
rare basin
#

right, but if it finds it does allocae the instance

sour dome
rare basin
#

so its no difference if you want to just check if a component exist

pallid nymph
rare basin
shell sorrel
#

also you can just define out in line

#

if you really are not using it

burnt vapor
rich adder
#

if(collider.TryGetComponent(out TheComponent _)

rare basin
#

if you just want to check if a component exist

#

no point of using TryGetComponent

#

and allocate the out result

rich adder
#

thats why discard exists though

burnt vapor
#

So GetComponent is probbaly just best here. Even if there was a difference in allocation I doubt it's fitting for #💻┃code-beginner

hexed terrace
rare basin
burnt vapor
rare basin
#

how is allocation onyl related to editor?

burnt vapor
#

So how does this save allocation

shell sorrel
#

either way find it odd wanting to check for the existence without wanting the reference to the component

rare basin
pallid nymph
#

in Editor it creates a fancy object for nicer errors, blabla

rare basin
#

right, but we are talking about TryGetComponent

#

and a difference between these two

pallid nymph
#

yes, one will not allocate in the editor

shell sorrel
#

yeah did not realize is a editor vs build thing, but difference is the cost of the UnityEnigne.Object wrapper for a native object

pallid nymph
#

also - no one cares, unless they're running Unity on a toaster, so 🤷‍♂️

rich adder
rare basin
pallid nymph
#

to null

shell sorrel
#

the cost is the thing the reference points to not the reference

burnt vapor
#

For your information, TryGetComponent still allocates for returning a variable, even if the component does not exist.
https://github.com/Unity-Technologies/UnityCsReference/blob/master/Runtime/Export/Scripting/GameObject.bindings.cs#L179C53-L179C62
So this does not at all make a difference in terms of performance, even if the result is null

GitHub

Unity C# reference source code. Contribute to Unity-Technologies/UnityCsReference development by creating an account on GitHub.

pallid nymph
#

TryGetComponent is faster in the editor than GetComponent - that's the main difference

rare basin
burnt vapor
cosmic dagger
#

the main difference is speed in the editor . . .

pallid nymph
#

am at work, can't be bothered, but that's the main point of it

rare basin
#

but you are talking about totalyl different thing

pallid nymph
#

in Editor, it wouldn't need to allocate... in build they're the same, just slightly different

rare basin
#

than we are

#

no one said anything about editor

#

and you started some editor performance dicussion

pallid nymph
#

in build it doesn't matter much

#

use whichever one you prefer in terms of code style 🤷‍♂️

rare basin
#

we are talking about allocation, and that if you just want to check if a comopnent exist, it is better to use GetComponent instead of TryGetComponent

pallid nymph
#

why?

rare basin
#

idk scroll up

pallid nymph
#

neither is allocating in builds

brave compass
shell sorrel
#

why are we even still talking about this, i incorrectly brought up a behaviour of it i thought was not only editor only and discovered it was after reading docs

pallid nymph
#

I define allocating as getting new heap memory - neither Get nor TryGet does that in builds

sour dome
#

different question than that GetComponent this time, I had SpawnEnemy() but now I want to pass in a difficulty level, but nameof() won't take a parameter right?

burnt vapor
rich adder
#

they're better, you can pass parmaters

rare basin
#

that there is no difference

#

and they said it's better to use try over that

rich adder
#

better is subjective here

rare basin
#

didn't sound subjective

rich adder
#

I prefere typing TryGet even when using _ and dont need component

burnt vapor
#

I don't, so are we even now in terms of what is better?

pallid nymph
#

I prefer != null, but that's because I'm used to it from before the TryGet time 😄

shell sorrel
rich adder
#

its preference at this point

rare basin
sour dome
shell sorrel
rare basin
shell sorrel
#

StartCouroutine(SpawnEnemy(2));

rare basin
rich adder
hexed terrace
shell sorrel
sour dome
#

it's telling me to use nameof instead of a string literal

cosmic dagger
rare basin
shell sorrel
rare basin
#

StartCoroutine(SpawnEnemy(0))

rich adder
rare basin
shell sorrel
rare basin
#

he doesnt have 2 parameters in his function

rare basin
#

StartCoroutine(SpawnEnemy(0));

shell sorrel
# sour dome

look at the example i am calling it StartCoroutine(SpawnEnemey(0));

#

where the ()s are matter alot

sour dome
rare basin
#

who said that

sour dome
hexed terrace
#

I know you're a beginner, this is something very basic. Don't blindly copy from elsewhere, think about if the suggestion fits with what you have

shell sorrel
#

more or less your IEnumerator method is called with what ever args it needs then start coroutine runs on its returned value

sour dome
grizzled surge
#

Is there a way to see the collider that character controller has?

rich adder
#

also not code related

hexed terrace
grizzled surge
#

oh yeah right sorry

modest basin
#

How to understand the language

hexed terrace
#

learn

rich adder
sour dome
#

So if I understood coroutine correctly is that you can pause/resume it. Which means, I can "pause" the spawner when the player meets a condition, increment the difficulty, and the resume the coroutine to spawn different enemies right?

rare basin
#

always suprised people ask such question

sour dome
#

Or does the coroutine needs to be reset to apply the new difficulty value?

shell sorrel
shell sorrel
#

to do that you need to save the return of StartCorutine so you have a handle to it

#

and can later call StopCoroutine on that handle

rich adder
#

Although could technically pause a coroutine if you use a while loop inside

shell sorrel
#

well yeah cool set a bool, and have it just yield frames

rich adder
#

using something like WaitWhile

#

ya

night sparrow
#

Can anyone help me with TextMeshPro text not been set?


using System;
using Photon.Pun;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

// I have the public class and stuff just not included

    public TextMeshPro damageIndicatorText;
    public GameObject damageIndicatorParent;

// Inside some other code I have the 

// SetDamageIndicator(25);

    void SetDamageIndicator(int damageValue)
    {

        Debug.Log(damageValue);
        damageIndicatorText.text = "Damage";

        Debug.Log("Animating damage indicator.");
    }

It Debugs the correct Number but the text Is never getting set like to anything

shell sorrel
#

though if you want something running for the applications life time you turn on and off. personally i would just use the Update method

#

and keep track of deltaTime

hexed terrace
rare basin
#

TextMeshPro pretty sure thats not a proper type for 2d

night sparrow
#

So i need to use TMP_text for

head tags and stuff?

hexed terrace
#

damageIndicatorText.text = "Damage"; do you want it to just say Damage ?

shell sorrel
#

so hoping for just floating worldspace text, or got a worldspace canvas for it?

night sparrow
#

It should say the Provided Int but it wasn't so i just set to a string to see if it was the int breaking it

hexed terrace
#

damageIndicatorText.text = damageValue.ToString();

steel smelt
#

Is the ref assigned in the inspector?

night sparrow
shell sorrel
#

pretty sure foo is right here

night sparrow
#

Huh?

shell sorrel
#

though you would get a nullref in that case

night sparrow
#

I set it inside the script / inspector

hexed terrace
#

do you get the Debug.Logs?

night sparrow
shell sorrel
#

did you try it with TMP_Text as the type

hexed terrace
#

You're gonna need to do a screen recording and show us what's happening, we're just poking around in the dark

night sparrow
# hexed terrace do you get the Debug.Logs?
25
UnityEngine.Debug:Log (object)
GunController:SetDamageIndicator (int) (at Assets/Scripts/GunController.cs:179)
GunController:Fire () (at Assets/Scripts/GunController.cs:164)
GunController:Update () (at Assets/Scripts/GunController.cs:95)
night sparrow
shell sorrel
#

also are you calling the code on the right object

hexed terrace
#

won't make a difference changing the type

shell sorrel
#

are you calling it on your prefab instead of the intance of it

night sparrow
shell sorrel
#

Since no errors feels like it's not executing where you think it is

night sparrow
#

Makes even more weird as I have attempted with the name tags

The name tags code works fine and I tried making the Damage indicators code the same and it was the same and still would not show the text as damage

Like the Nametags, is the same as the Damage but the nametags work for some reason

hexed terrace
# night sparrow

so the guncontroller references the dmg text on itself.. which seems wrong

#

It's gonna update the text above you, when damaging the enemy

#

So, if you have the scene view and game view visable at the same time, I bet when you do damage, it works.. but not on the tmp you expected

night sparrow
#

Yes it does and i feel dumb asf

hexed terrace
#

we've all been there

violet smelt
#

Anyone know how I can implement a schedule system for this school rpg im makinng?

#

As of now I have prefabs of npcs in different groups, i then assign a location for each group if that makes sense

stark ruin
#

Hi guys,when 2 objects collide how can i disable the vincolar reaction between the 2 objects?

#

like let's say the 2 objects collide,object1 adds a force on object2

#

but object2 doesn't add a force to object1

foggy magnet
#

Not really sure best place to ask this, as I couldn't see a PlasticSCM channel.

Every time I hit play, my render textures are changed, and this change means PlasticSCM is constantly wanting me to check in the changes.

I'm not sure what the recommended solution to this is? Is it to do with ignoring, or hiding, those changes? Or something else entirely?

frigid sequoia
verbal dome
#

Yeah something like that

#

I think you can emit multiple bursts but not sure

frigid sequoia
verbal dome
frosty hound
latent zodiac
#

Hi all, I'm trying to load an image located on another disk to a Texture2D to be used in an image visual element as part an editor window, and I'm trying to use ImageConversion.LoadImage. When I debug log the file path it outputs correctly with the file path of the image, however when I use the LoadImage function I get a directory not found error. The weird thing is that the error log outputs a path which has the project path appended onto the image path for some reason. Anyone got any ideas on why this is or how to fix?

languid spire
frigid sequoia
latent zodiac
brave compass
frigid sequoia
#

I mean, is not much different of setting it manually from an animator that plays sound of something like that, but would have to do

languid spire
latent zodiac
#

That's likely because I'm using a package to interface with OpenAI and grabbing the result

languid spire
#

remove the file:// from the front of the path and it should work. fyi file protcol is, correctly, file:///

latent zodiac
#

ok that makes sense, i totally glossed over the file:// at the start and assumed the path was correct cause it downloaded correctly

#

bit stupid of me

languid spire
#

it looks like you should be using Application.persistentDataPath anyway

latent zodiac
#

is that what I should be using for external files?

languid spire
#

yes

#

that will work in the Editor and in a Build

latent zodiac
#

apologies for my ignorance but that looks like it references a separate specific folder, the images are being generated in their own specific folder and i just need to load the currently generated image without moving it, your suggestion seems like when the images are generated i will need to move them into wherever Application.persistentDataPath points to

languid spire
#

yes, Application.persistentDataPath is the ONLY place where you are guaranteed to have both read and write access for data files

latent zodiac
#

Oh ok, is there no other reliable way to be able to read data outside of the project except for using Application.persistentDataPath?

rare basin
#

there are ways

#

but nothing built-in

languid spire
#

reading you can use UnityWebRequest

latent zodiac
#

I've seen some suggestions on using unitywebrequest on the forums

languid spire
#

but writing you should only use Application.persistentDataPath

latent zodiac
#

I don't want to alter the generated image I just want to read it and slap it onto a texture

#

so im guessing unitywebrequest is the way to go

languid spire
#

tbh it looks like it's in Application.persistentDataPath anyway

latent zodiac
#

it is

#

🤦‍♂️

#

if Application.persistantDataPath returns the directory location though how can I get the specific file I want

languid spire
#

if it returns the full path the Path class has methods for splitting it up

#

I guess result is coming from somewhere

latent zodiac
#

yeah result comes from the generation request

languid spire
#

then you'll probably be ok with just stripping off the file:// from the front

latent zodiac
#

application.persistantdatapath returns the correct folder it references in the documentation, mine being AT2, but I need to access a folder within called download_cache and then the current result

astral notch
#

Why is my character not falling here? The terrain has a one way platformer collider. All other normal terrain behaves properly

languid spire
#

Path.Combine @latent zodiac

violet smelt
#

How do I reference my navigation modifier through code?

latent zodiac
#

oh so I can use Application.persistantDataPath and combine it with the folder name and the file name of the result?

violet smelt
#

I want code changing it from walkable to unwalkble

astral notch
rare basin
#

saveFilePath = Application.persistentDataPath + "/saveData.bg"; i have this for example

astral notch
#

as you can see the collider is traced around desired area

latent zodiac
#

ill give it a shot, much thanks for the help @languid spire @rare basin

polar acorn
cosmic dagger
latent zodiac
#

this is surprisingly way more annoying than I thought it would be sheesh

languid spire
latent zodiac
#

oh working in editor only is fine

#

im using it for an editor tool

languid spire
#

then I think stripping the file:// is your best bet

latent zodiac
#

i still run into the issue of not being able to load external files right? cause i cant use ImageConversion.LoadImage cause it needs to be in the project directory and I cant use texture.LoadImage or something like that either

languid spire
#

no you are good, it is the file protocol that wants to be in the projects folder not the File.ReadAllBytes

latent zodiac
#

ok that worked wonderfully

#

all that time i spent just because of the file:// in front of the path, crazy how I missed that

#

thanks again @languid spire , knowledge and guidance is very appreciated

languid spire
#

not enough time learning front end Web Dev

latent zodiac
#

ye thats foreign territory to me if it wasnt obvious

languid spire
#

np, lesson learned I hope

latent zodiac
#

learned a fair bit today 🙏

languid spire
#

excellent, then my job is done

fading rapids
#

why at line 23 do i put a semicolon at the start

#

if i dont it gives error

polar acorn
fading rapids
#

oh wait i didnt put it on 22

#

mb

polar acorn
#

This is perfectly valid C# syntax:

Debug
  .
    Log
      (
        "Hello world"
      )
    ;
#

As long as you aren't splitting a symbol, C# doesn't care how many lines your one statement spans

fading rapids
#

i understand

#

ty

wind raptor
#

Is something like this okay? Where I have a static instance of a Monobehaviour object to be referenced by outside scripts?


public class Person : MonoBehaviour
{
    public static Person UnknownPerson { get; private set; } = new Person();
    string fullName = "";
    int age;

    private void Awake()
    {
        if(UnknownPerson.name == "")
        {
            UnknownPerson.name = "Unknown";
        }
    }
}
polar acorn
languid spire
polar acorn
#

You've essentially made a Single-Scene Singleton

#

if it only ever needs to exist in one scene, it's fine as-is (once you remove the invalid default value for UnknownPerson)

wind raptor
#

I don't want Person to be a singleton though. I just want to provide global access to a specific instance of Person

#

Yeah, single scene

languid spire
#

that is what a Singleton is

wind raptor
#

Any way to get UnknownPerson to exist at compile time?

#

In case I want other classes to have access to it?

#

Say my family class has a person isntance. I want that person instance to start as UnknownPerson

languid spire
#
private void Awake()
    {
if (UnknownPerson == null) {
       UnknownPerson = AddComponent<Person>();
        
            UnknownPerson.name = "Unknown";
        }
    }
prisma scroll
#

hey y'all, who's familiar with Behaviour Tree, Behaviour designer in unity, i need help

wind raptor
naive lion
#
    {
        if (other.gameObject.layer == LayerMask.NameToLayer("Environment"))
        {
            Debug.Log("Test");
            Destroy(gameObject);
        }
    }```
Hey guys do layer checks not work within OnTriggerEnter
I even did a public Layer myLayer and still doesnt seem to detect it
wind raptor
#

Hmm. K. Not sure I love that. I'll mess around with it

languid spire
#

is OnTriggerEnter even being called?

naive lion
#

i have another check for player

#

works fine

languid spire
#

in that case debug the gameObject.layer

final kestrel
#

Hey. Its me again T_T... I have this script here and it works zooming in and out. But it is zooming in and out too fast. I tried to lerp but nothing seemed to have changed. I read the documentation but did not understand..https://hatebin.com/tioqekaihg help me pls.

errant spear
#

Anyone knows what could it mean ?(the last errors, i think the warning are just linked to that) but the Error seems a bit obscure when i doubleclick on it it leds me to "edge.cs" and i don't know what it is

#

Seems linked to that "localScale" part

supple citrus
#

You’ve referenced a gameobject in your code but not actually dragged it into the reference

languid spire
supple citrus
#

Oh?

queen adder
#

Yeah Thats in the UnityEditor Namespace meaning its a Unity side error

supple citrus
#

My bad

#

Never seen that

polar acorn
queen adder
#

Just restart Unit yand it should fix itself

polar acorn
#

the other ones are likely actual warnings

languid spire
#

that, generally, changing scripts whilst in Play mode

errant spear
#

Ok i restart and tell you

hybrid gust
#
 public void Update()
 {
     var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
     RaycastHit hit;
     if (Physics.Raycast(ray, out hit, 10f))
     {
         Debug.Log(hit.collider.name);
         Vector3? closestPoint = null;
         if (hit.collider == gameCollider)
         {
             if (SnapToValidPoint(hit.point, out closestPoint) && closestPoint != null)
             {
                 highlighter.transform.position = (Vector3)closestPoint;
             }
         }
     }
 }

 private bool SnapToValidPoint(Vector3 collisonPoint, out Vector3? _closestPoint)
 {
     Vector3 cachedPoint = Vector3.one * Mathf.Infinity;
     bool foundSnappablePoint = false;
     foreach (var thing in placementGrids)
     {
         for (int x = 0; x < thing.gridWidth; x++)
         {
             for (int y = 0; y < thing.gridHeight; y++)
             {
                 if (Vector3.Distance(collisonPoint, thing.playPositions[x, y].position) <  Vector3.Distance(cachedPoint, thing.playPositions[x, y].position) )
                 {
                     cachedPoint = thing.playPositions[x, y].position;
                     foundSnappablePoint = true;
                 }
             }
         }
     }
     if ( foundSnappablePoint ) { _closestPoint = cachedPoint; return true; } else { _closestPoint = null; return false; }
 }

Any ideas as to why the snapping is so jank?

queen adder
#

I get that error when i a script was on a gameobject and then i delete a script or change the name of it

ornate osprey
#
hybrid gust
stark ruin
#

Hi guys,when 2 objects collide and they are all dynamic objects how can i do that the collision of the 2 objects in calculated just via script?

#

like let's say that the player1 moves and hit player2,i don't want that unity3d calculate the collision between the 2 objects by default

languid spire
stark ruin
#

let's say that there are 2 objects player1 and player2

#

player1 moves and hit player2

languid spire
stark ruin
#

let's say that player1 has a mass of 1kg and player2 0.01kg,i don't want that if player1 has a velocity when it hit player2 player2 moves if there is not a script who control the force that player2 has to receive

languid spire
#

ok, once again you say what you dont want, now read my question again

stark ruin
#

ok when player1 hit player2 i want to move player2 just via script using a force

hybrid gust
#

is player 2 kinematic?

stark ruin