#💻┃code-beginner

1 messages · Page 589 of 1

edgy tangle
#

You are. I missed it

#

Yeah so you should use Debug.Log(“here’s what I want to show in the console”);

#

For example when you call Jump, in the first line in the function you could put Debug.Log(“Jump”);

#

If that never prints then you know the function call failed

smoky river
edgy tangle
#

Up to you, but if you put it in the function then it will print every time the function is called successfully

polar acorn
#

Wherever you want it to print

smoky river
#

i want it to print whether grounded = true or false right before it calls the jump function how do i do that

edgy tangle
#

Well since you’re checking in update it will spam unless you gate it somehow

polar acorn
naive pawn
edgy tangle
#

If Jump is never called, that means grounded is always false when you check for input

#

Because that is the condition you wrote

smoky river
#

look at the error

naive pawn
#

noone told you to use Console.WriteLine

smoky river
#

how do i print in unit

#

iunity

smoky river
naive pawn
#

that's for bare c#, unity doesn't take that

rich adder
edgy tangle
rich adder
naive pawn
smoky river
polar acorn
# smoky river

Where did you get Console.WriteLine from. Everyone here told you how to print something in Unity

rich adder
#

Debug.Log throwing errors? I gotta see this..

smoky river
#

like ts

rich adder
naive pawn
wintry quarry
#

show your code and the error

rich adder
#

At most you'd get ambiguity error

naive pawn
#

(i'd guess it was placed wrong...)

rich adder
#

or that

cosmic quail
polar acorn
#

That would cause that line to throw an error

naive pawn
#

oh the if doesn't have braces, so putting the log where the writeline is now would call Jump every frame lmao

wintry quarry
#

Or they did using System.Diagnostics as nav implied

polar acorn
#

But actually saying what the error is would be a good idea

rich adder
#

I'm at the edge on my seat.

naive pawn
#

please do not your seat

wintry quarry
rich adder
#

therelol

wintry quarry
#

thank you

rich adder
#

😅 my eng skills

#

OP retired

edgy tangle
#

Well he was met with a dog pile

#

But yes Mr. E please show your code with the Debug.Log and the error that comes from using it

smoky river
#

analogy kinda sucks but i couldn't think of a better one

edgy tangle
#

Otherwise what you’ve said makes no sense

rich adder
edgy tangle
rich adder
smoky river
#

and it worked but idk where i'm supposed to find the results

wintry quarry
#

wdym you forgot what it said... just go look and show us

rich adder
#

you said it errored, we just wanted to see which error is it and where you put the code

wintry quarry
smoky river
polar acorn
#

Wherever you put it, it hasn't run

wintry quarry
smoky river
#

yes it doesn't work

wintry quarry
#

ok so show us where you put the log

smoky river
cosmic quail
# smoky river

congrats this is called debugging! you found out that this part of the code doesnt run, now you can continue trying to fix it

rich adder
#

dammit..unconfigured iDE..

wintry quarry
# smoky river

oh gosh - well now because you're not using braces for your if statement you've also made it so jump runs every frame as well

polar acorn
# smoky river

So, the log isn't printing because the if condition is never true.

Also, you're calling Jump() every frame now, it's not part of the if. You don't have any braces

wintry quarry
#

you really need to use { } for if statements in C#. It's not Python.

edgy tangle
#

Yes if you put line breaks in your code for a single block you need to wrap that into {}

wintry quarry
#

well more the ; that matters but yea

smoky river
wintry quarry
smoky river
wintry quarry
# smoky river

Anyway you actually need to stop everything here and get your IDE configured

naive pawn
polar acorn
naive pawn
polar acorn
#

If you want a condition to contain multiple lines, you will need to use braces

rich adder
#
if(something)
//runs through if statement - without {} if statement only affects first line under it
//always runs no matter what if statement does

if(something){
//runs through if statement
//runs through if statement
//etc.
}```
@smoky river
edgy tangle
cerulean badger
#

what's more appropiate for combat system: Duplicate an already existent hitbox object from the hierarchy or instance it entirely via script?

polar acorn
rich adder
#

object pool is godsent

edgy tangle
fast fern
#

Hi I'm new to C# (I have limited experience with python), I wanted to ask
what do you call stuff like these? operators?

cerulean badger
naive pawn
polar acorn
rich adder
polar acorn
# cerulean badger it's basically grouping?

It saves time having to spawn new copies of things by keeping the old ones around and just turning them off when they're done. Then you can move them to where they need to be and re-activate them

fast fern
#

I'm not sure, I'm trying to figure out all the terminology (my english is not good)

naive pawn
polar acorn
smoky river
wintry quarry
#

Actually decided I don't have the patience to teach programming from first principles to someone today.

polar acorn
fast fern
naive pawn
#

that's a method, yes

#

python also has these

rich adder
#

you will pretty much learn alal this stuff as you do the c# course or check out the manual

fast fern
#

aaah I see

polar acorn
fast fern
#

I thought functions and methods are only void/int/strint exmaple(){

}

naive pawn
#

that's a method declaration

#

it's still a method when you call it

#

somewhere in the source code, there's also int Range(int begin, int end) {}

fast fern
#

long long way to go for me lol

rich adder
polar acorn
naive pawn
#

Type MethodName(Type param) -> method declaration
MethodName(arg) -> method call

#

MethodName itself is the method

fast fern
#

alright, thanks for the explanation guys, that was fast :D✨✨✨

cerulean badger
rich adder
polar acorn
smoky river
rich adder
#

unity object pooling doesn't even prewarm so does nothing in the start of the game

#

pooling kicks in when the capacity limit has hit

naive pawn
cerulean badger
trail heart
#

Why "duplicate" it if there can be only one? Which you could move around instead

smoky river
cerulean badger
#

oooh now I understand it, it substitutes instancing and destroying by activating and deactivating

rich adder
#

correct

cerulean badger
#

cool

rich adder
#

object pool is like a bucket of tennis balls, once you done throwing all the ones in bucket the oldest wants to come back in the bucket ready to be thrown again

naive pawn
cerulean badger
#

really cool, ty guys

smoky river
rich adder
naive pawn
#

show your current !code please 👇

eternal falconBOT
rich adder
#

we can't know whats wrong if you dont show us

#

a configured IDE should also be your priority since yours is not configured @smoky river

#

the errors aren't underlining in your IDE you need to fix that

polar acorn
cerulean badger
#

what do static variables do?

smoky river
#

@rich adder

polar acorn
rich adder
#

jk

polar acorn
#

I linked you the documentation

rich adder
smoky river
polar acorn
#

please attempt to learn how to use C# instead of just guessing randomly

rich adder
#

it should be lit up with Greens and yellows

polar acorn
rich adder
#

!ide

eternal falconBOT
rich adder
#

@smoky river

smoky river
smoky river
rich adder
smoky river
#

it

naive pawn
polar acorn
naive pawn
rich adder
smoky river
#

i'll just ask chatgpt for the error and make it actually help me with the code

naive pawn
#

we aren't gonna just copy+paste everything in the tutorials to you

rich adder
#

oh boy

#

also goodluck with this one guys 🚶

naive pawn
polar acorn
#

But sure, go do that, just stop wasting our time here

rich adder
#

be mindful of peoples free time goddamit. Wasted all this time just to get a response a 6 year old gives

#

"I'm not doing it nuh huh"

#

child then go away

minor atlas
#

can someone help me i want to change scene in my unirt projectg but i cant here is my code:using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;

public class SceneManager1 : MonoBehaviour
{
// Start is called before the first frame update
public void SceneChanger()
{
SceneManager.LoadScene(1);
}
}

#

i created empty object

minor atlas
#

then

eternal falconBOT
rich adder
minor atlas
rich adder
#

SceneManager1 this is a horrible name , try to stick away from already taken names by Unity API

minor atlas
#

i am doing a moblie gameand i want to change the scene with button

#

i have a button

rich adder
minor atlas
naive pawn
#

@edgy tangle
control flow statements if, if/else, for, foreach, while, do..while take a single substatement as the body of control flow statement
so for example, if has the form "if ( cond ) stmt"
{ } is a special statement, the block statement
it takes several substatements and runs them in order
so when you provide a block statement to if, the if just sees that single block statement as its scope
if it's not a block statement, no real difference, if just sees that statement as the scope instead
; is also a special statement, the empty statement, it does nothing, if (x); doesn't do anything even if x is true (assuming the condition doesn't have side effects of course)

this also means that if/else if/else technically isn't a construct of its own, it's just an if/else nested inside another if/else

switch and try..catch..finally have the braces as part of their syntax, rather than using a block statement, so you can't use single statements for those (i mean, obviously not for switch)

rich adder
trail heart
minor atlas
rich adder
#

if not most likely you either configured button wrong, or dont have event system

minor atlas
#

i hav eevent system

rich adder
#

okay so more reason to log the button click

minor atlas
#

ok i will do it

#

it doesnt work

#

at all

rich adder
#

so we dont know what "it" is

minor atlas
rich adder
minor atlas
#

it doesnt work

trail heart
rich adder
minor atlas
#

i did it

rich adder
echo ruin
#

You made an empty method that just lives in the void

minor atlas
rich adder
minor atlas
#

this is the button

minor atlas
echo kite
rich adder
#

if you have other UI elements its likely they are getting blocked

trail heart
# minor atlas

I believe Buttons don't work with a Sprite Renderer
They'd have to have an Image as the Target Graphic

rich adder
# minor atlas sorry

just like I said, Pullup the Event System during PLAYMode you should see a black bar at the bottom click it

trail heart
#

Sprites are not meant for UI

minor atlas
#

where?

cosmic dagger
# minor atlas

Button component is for UI, not for a SpriteRenderer, which is for a 2D GameObject . . .

minor atlas
polar acorn
trail heart
#

By creating a new Button game object, you'll get one that's set up with the correct components
(Not a new Button component)

cosmic dagger
rich adder
#

you cant put a button on anything but UI elements

#

raycast wont detect the area outside of canvas

minor atlas
rich adder
trail heart
rich adder
#

UI -> Buttons -> TMP Button

#

or whatever it is

minor atlas
rich adder
#

after that Ideally your raycast will finally hit it, unless you made the Text objects be above by accident

minor atlas
#

it doesnt work

#

@rich adder

polar acorn
minor atlas
polar acorn
rich adder
#

literally did nothing diffeent lol

minor atlas
#

mb

polar acorn
#

we told you to make a new one properly using UI

minor atlas
#

wait

#

i did

polar acorn
#

So then why did you show us the same button again

edgy tangle
#

I do appreciate the additional info tho

rich adder
minor atlas
#

BTW

#

THANK YOU

#

IT WORKED

#

but not

#

i mena the scene changed

#

but its one of the things there

rich adder
#

wut?

minor atlas
#

not everything the bg is not there thu buttons and etc

#

mb

#

everything is gone

polar acorn
#

Does that scene have a background and buttons

minor atlas
#

idk why

rich adder
minor atlas
#

it had everything there

rich adder
#

if the scene is like that then you had it like that

minor atlas
#

but now is gone

#

no

rich adder
#

or you're swithicng to the wrong scene

minor atlas
#

i really did smth

#

but its gone

#

idk why

rich adder
#

then you did not save?

minor atlas
#

I DID

rich adder
#

things dont magically disappear

minor atlas
#

I HAD SAVED IT AND

#

IT WAS THERE

#

COUPLE TIMES

lost torrent
#

Hi, I created this interface called ITimeTracker, but when I go to link it to another script the option for my interface isnt there. Does anyone know why?

minor atlas
#

BUT NOW ITS GONME

rich adder
#

then you're loading the wrong scene

cosmic dagger
slender nymph
eternal falconBOT
rich adder
cosmic dagger
eternal falconBOT
minor atlas
#

mb

#

again

#

its there

rich adder
#

double smackk

rich adder
minor atlas
#

but its not focuse

#

focused

#

form the camera

#

idk why

rich adder
#

also please chill out with the vertical messaging

snow jewel
#

for the game im creating, i have it where if the player collides with this power up prefab, it should spawn a clone of the player but for some reason whenever the powerup is collected, the game freezes.

the clone does spawn so idt thats an issue; i think it might be somehting to do with how i assigned the player game object in the inspector. I made my player object a prefab and assigned that prefab in the inspector of the clonecontroller powerup cuz i couldnt assign the actual player game object from the hierarchy. lmk if you want me to explain something for a better understanding

btw the debug.log for the player position does show up in the console

CloneController script: https://paste.ofcode.org/?edit=PWZBREhxXJFGSEvWL2sPNW

PowerUpClone script: https://paste.ofcode.org/zTLwgWjaEtLjjHm6VR5T27

polar acorn
polar acorn
cosmic dagger
polar acorn
snow jewel
#

alr one sec

#

this is the prefab that is being instantiated

naive pawn
snow jewel
polar acorn
slender nymph
#

when you say it is "freezing" are you referring to the entire unity editor becoming unresponsive to input, or does only game mode stop working? because those imply different things

snow jewel
snow jewel
slender nymph
#

then you have an error that you are ignoring and you just happen to also have error pause enabled

polar acorn
slender nymph
#

actually wait, if your in game joystick is working that's not even the case. the game isn't freezing, things just aren't working the way you expect

snow jewel
polar acorn
# snow jewel here

Okay, no errors, ClonePlayer exists... I don't think the cloning process has anything to do with this issue

snow jewel
#

hold on lemme try something

cosmic dagger
polar acorn
snow jewel
slender nymph
#

while we wait for this video i'm gonna go ahead and guess that timescale is getting set to 0 or something

snow jewel
#

hold on i moved my scripts to a different folder now its giving me random errors lemme try fixing it first

#

nevermind

#

i fixed it

#

its good now

slender nymph
#

what ended up being the issue?

snow jewel
#

im pretty sure i had two scripts on the powerup prefab both of them were interfering with the collecting logic

#

i removed one of them and it works now

slender nymph
#

that shouldn't have affected everything else unless it was doing something like setting timescale to 0 🤔

cerulean badger
cerulean badger
#

21

polar acorn
#

Then hitbox is null

cerulean badger
#

but I have a parameter assigned to Hit method when I click, so this parameter is used to define the hitbox object

slender nymph
#

and yet nothing named "Punch" exists in the scene

cerulean badger
#

but it does right here

slender nymph
#

did you bother looking at the documentation for GameObject.Find?

polar acorn
#

Find doesn't work on disabled objects

cerulean badger
#

oh

polar acorn
#

Why use find at all? Just assign the reference directly

cerulean badger
#

wdym

#

like, there will be more than one attack so I'll need to call the same method but with other stuff as parameters

polar acorn
#

So pass an object reference to the function instead of a name

kind timber
#

!docs

eternal falconBOT
kind timber
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

opaque lichen
#

How do i refrence the camera in a script in a chaacter to transform the camera?

#

i tired private GameObject = gameobject.FindObjectByTag("MainCamera"); but that doesnt seem to work

cosmic dagger
opaque lichen
#

yeha

#

i just forgot it there

#

like wahts that mean

verbal dome
#

You put it in a field initializer and it's not allowed

#

Field initializer meaning the place you declared the variable as a class member

patent stratus
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

wintry quarry
#

or - just use Camera.main which is a shortcut to get the main camera

opaque lichen
#

bro c#

#

makes no sense to me

wintry quarry
#

you'll learn it if you keep it up

opaque lichen
#

So basically when the character collides with a trigger I want it to move the camera to the right

#

or wtv

#

So I use ontrigger function

#

But the collider is refernece how??

wintry quarry
#

Why do you need to reference the collider

#

You're using OnTriggerEnter I thought

opaque lichen
#

Collider.gameobject.CompareTag doeesnt work

#

how else?

ashen frigate
wintry quarry
#

you would use that parameter

opaque lichen
#

ahhh

#

ok

#

wrong

wintry quarry
opaque lichen
#

thuiing

#

bro what are classes on godf

wintry quarry
#

The class describes how the object behaves, what data it holds, and what method are available to run on it

#

every instance of the class will follow that template

#

THis is the essentail abstraction of Object Oriented Programming

opaque lichen
#

Oh so the colider is a 2dBoxColider by class?

wintry quarry
#

BoxCollider2D

opaque lichen
#

yeha

#

thats its class?

wintry quarry
#

yes

#

WHich is a subclass of Collider2D

opaque lichen
#

mhm

wintry quarry
#

All BoxCollider2Ds are Collider2Ds

opaque lichen
#

I get it now

#

so anything in green is a class?

#

in my code

#

mostly

wintry quarry
#

That depends on the specific settings of your code editor

#

maybe

#

It might be that green is all type names

opaque lichen
#

yeah

wintry quarry
#

There are other things that are types that aren't classes

#

Such as enums, structs, and delegates

opaque lichen
#

yeah

#

so a type of thing isnt its class?

wintry quarry
opaque lichen
#

brain cant comprhened this stuff

#

i thought roblox scripting could get hard

#

this is omehting else

#

cant even compare

wintry quarry
wintry quarry
opaque lichen
#

yeah

#

Lua is lighjt

#

but comming from lua this is so confusing

wintry quarry
#

The main thing is that LUA isn't object oriented. SO this is your first foray into object-oriented programming

#

it's definitely a new concept

opaque lichen
#

i though it was object oriented

wintry quarry
#

if Lua was object oriented it would have classes

opaque lichen
#

i thought object orientated means that u work with objects that each have their own methods and properties

wintry quarry
#

lua has pure functions

opaque lichen
#

and the heirarchy was really easy

#

if u want to get to any object

#

u just start form ur workspace

#

and go through each parent

wintry quarry
#

You're also now conflating LUA with Roblox btw

#

that is a Roblox thing you're talking about

opaque lichen
#

yeah thats true

#

but thats all i have really programmed

#

and pyhton

#

ab it

wintry quarry
#

both of those are also dynamically typed languages

#

so there's two big different paradigms you will need to get used to here:

  1. C# is object oriented
  2. C# is statically typed
#

Static typing means you need to explicitly say what type each variable is

opaque lichen
#

yeah

wintry quarry
#

in python you can just do:
x = 5
in C# you must do:
int x = 5;

opaque lichen
#

yeah I got used to that

#

just struggle to refer to what I want to

wintry quarry
#

You'll get used to it, then it will become second nature

opaque lichen
#

liek this doesnt wokr me me

#

idk why

wintry quarry
#

What doesn't work about it

opaque lichen
#

doesnt log Level1

wintry quarry
#

Is "Hit" being logged in the console?

opaque lichen
#

no

wintry quarry
#

THen the code isn't running at all

#

Which means you don't have the circumstances in the scene set up properly to get an OnCollisionEnter2D

#

I thought you mentioned earlier you were using a trigger colldier, is that correct? This won't work for a trigger

opaque lichen
#

wait sorry its this

wintry quarry
#

That's the 3D verison

#

you need OnTriggerEnter2D

#
void OnTriggerEnter2D(Collider2D other)```
#

also you should add a log outside the if statement as well to make sure the function is actually running

opaque lichen
#

yeah its iside the looped on

#

one

#

inside void update

#

it worked

#

cold

#

what i upadtre to

wintry quarry
#

collision is a confusing name for that parameter I would say

#

it's not a collision, it's a collider

opaque lichen
#

yeah first I had put the script in teh camera

#

and it tottaly didnt work

#

realized that the camera doesnt acc collide

wintry quarry
#

Yes it needs to be on one of the objects involved in the collision

opaque lichen
#

yeah then I put in the character now it works

native star
#

Hey guys, I'm new to Unity and need help translating my animator's equations and mechanics into Unity

molten dock
#

if i were to do Random.Range (0,2) would it never actually do a 2

native star
#

I want to know how to create a rig I can input angles into

wintry quarry
molten dock
#

ok thanks

wintry quarry
molten dock
#

do you think its odd that it does the 0 but not 2

#

not consistent logic

wintry quarry
native star
#

Yeah

wintry quarry
#

So did you try that? DId you have issues?

native star
#

I was wondering how I could make a little human and set pivots on it

#

I'm completely new and dont know where to start at all

echo ruin
#

Huh.. so doing 10, 0 would actually give a range between 0 and 10

native star
#

I play a game called Elite Engineering where you build with mechanical blocks and logic nodes

native star
#

I built a working animator on there and am trying to remake it

opaque lichen
#

is it possible to test equality on vector3?

wintry quarry
#

usually not a good idea to do it directly though

opaque lichen
#

How would I do that?

#

beacuse

#

if (obejct.position == vector3(1,1,1) obv isnt it

wintry quarry
#
if (someObject.transform.position == new Vector3(1, 1, 1))```
opaque lichen
#

yeah whys that bad?

wintry quarry
#

Because for one it's imprecise

#

it's very unlikely for the position to be exactly that

#

unless you explicitly set it to exactly that somewhere

#

what are you actually trying to accomplish with this code?

opaque lichen
#

move the camera through levels

#

like this

#

the box is the collider

wintry quarry
#

I don't see why you would need to do such a comparison to do that

opaque lichen
#

to check if the camera is in teh 2nd spot

#

to move the camera back

#

to teh orignal

#

if teh character went backwards

wintry quarry
#

For that kind of thing you would just have e.g. an array or list of camera positions and store an int currentCameraPositionIndex variable or something

#

to know where it currently is

#

Or better yet - use Cinemachine ClearShot

opaque lichen
#

yeah idk how to do both of those

#

so I was just thinking of the simplest method

fathom bramble
#

In Unity, what's the best way to preserve game state between scene loads? I use a pub-sub system for components to interact but for example, I want the score to be preserved between scenes. I currently use a static class to do this but I feel like maybe there's a better way?

wintry quarry
wintry quarry
opaque lichen
#

Well I gotta begin somewhere

crimson pike
#

real quick, want to load a scene from a file structure, tried calling Load on "Terrain/Simulation" (from the boot scene that would be the relative path)

opaque lichen
#

Idk what Im doing so it is how it is

crimson pike
#

"./Terrain/Simulation" doesn't work though

#

either

#

rather is it possible to not have to use the full absoluite path?

wintry quarry
cerulean badger
#

for my combat system, I'm trying to organize 2 things: The data from the attacks, like damage, cooldown, etc, and the enemies data. How or where I put these stuff?

crimson pike
wintry quarry
crimson pike
#

yeah, anyway just calling the scene name works

#

didnt think of that lol

opaque lichen
#

why is this so complicated

#

why cant I just make a list of strings

#

string[] list = ("Apple","Banana", "Orange")

#

how do i do this???

rich adder
opaque lichen
#

ah ok

ashen frigate
#

how can i manualy move to scene in the hierachy ?

rich adder
ashen frigate
#

like this

#

i dont want to delete it just like a keybind that let me change the scene to test stuff

#

even when i do this it wont change scene

rich adder
#

you have two scenes open

ashen frigate
#

(set active scene)

rich adder
#

just double click the scene file to open it single?

ashen frigate
#

yea i want 2 scene to be open to test stuff

rich adder
#

Are you trying to move an object from one scene to another or something?

#

cause idk what wanting 2 scenes open have to do with

even when i do this it wont change scene

swift crag
swift crag
#

Note that changing the active scene doesn't really do anything on its own, save for a few things like changing where your environment settings are coming from

#

Both scenes are still loaded

ashen frigate
#

can i move game object from scene 1 to scene 2 ?

swift crag
#

But I'm still very unclear on what the actual objective is

#

especially given this image you sent

spring coral
#

if anyone here used the videoplayer component before, quick question

#

the .frame property isnt updating for whatever reason and i cant seem to find out why? the videoclip is clearly playing and .isPlaying is being reported back and im a bit stuck here

#

the same happens with the .time property

novel olive
#

hi does anybody know why cant i see bake tab? in unity 6000.0.35f

rich adder
#

btw this a code channel

bold plover
#

I accidentally clicked "generate as new type" while refactoring. How does one undo the creation of the namespace within Visual Studio?

teal viper
bold plover
#

Found it in my files. Thanks!

exotic jacinth
#

I’m running into an issue with the zombie animation states. Initially, the zombie wasn’t moving in the Update method, so I used a coroutine to fix that. However, after making this change, the animations are now looping continuously between walking and attacking, even when the zombie should be either walking or attacking based on its distance to the target.

I’m using the remainingDistance and stoppingDistance to transition between walking and attacking, but it seems like the transitions are happening too quickly. The zombie switches between these two states without properly completing either one.

csharp
using System.Collections;
using UnityEngine;
using UnityEngine.AI;

public class ZombieController : MonoBehaviour
{
    public Transform target;
    private Animator animator;
    private NavMeshAgent agent;

    private void Start()
    {
        animator = GetComponent<Animator>();
        agent = GetComponent<NavMeshAgent>();
        

        
        StartCoroutine(UpdateDestinationEvery10Seconds());

    }

    private void Update()
    {
        
        if (agent.remainingDistance > agent.stoppingDistance)
        {
            animator.SetBool("isWalking", true);
            animator.SetBool("isAttacking", false);
        }
        else
        {
            animator.SetBool("isWalking", false);
            animator.SetBool("isAttacking", true);
        }
    }

    private void TrySetDestination()
    {
        
        
            agent.SetDestination(target.transform.position);
        
    }

    
    private IEnumerator UpdateDestinationEvery10Seconds()
    {
        while (true)
        {
            TrySetDestination();
            yield return new WaitForSeconds(1f);  
        }
    }
}
fast fern
#

so when I write my code, I can't seem to have options pop up like here, any reason why? (tried on monodevelop, Godot C#, and visual studios)

slender nymph
#

!IDE

eternal falconBOT
echo ruin
exotic jacinth
#

My animation transitions are set up like this in the Animator:

I have states for Idle, Zombie Walk, Attack, and Dead
I use parameters like isWalking and isAttacking (both Boolean) to control the transitions between these states.
For example:
Idle → Zombie Walk happens when isWalking = true.
Zombie Walk → Attack happens when isAttacking = true.
Transitions back to Idle or Walk occur when these parameters are false.
I have disabled hax exit time for all

#

And I have set stopping distance =5

echo ruin
#

If the attack animation is not looping, i.e. just one animation, you can enable has exit time and just set it to 1 (one cycle), then you’ll save a lot of code and conditions, since you can just use animator.Play(“name of animation”)

#

Also there’s an animation channel

exotic jacinth
gilded void
#

I'm a beginner, and I've been struggling for about 1.5 hours trying to get it to work properly.

sacred cradle
#

are the wheels colliding with the vehicle body?

#

if so, make sure to make the wheels have there own layer, then exclude that layer in the vehicle body collider

gilded void
#

The wheel colliders stay where they should, but the wheel meshes don't go to the correct positions.

sacred cradle
#

thats really strange

sacred cradle
# gilded void The wheel colliders stay where they should, but the wheel meshes don't go to the...

try having empty game objects where your wheels are, then making your wheels children of the empty game objects (like wheel holders for each wheel), then change the UpdateWheel function to set the local position to 0 0 0, and then change the local rotation for wheel spinning. I think something like this:

    void UpdateWheel(WheelCollider col, Transform trans)
    {
        Vector3 position;
        Quaternion rotation;
        col.GetWorldPose(out position, out rotation);

        trans.localPosition = new Vector3(0, 0, 0);
        trans.rotation = rotation;
    }

you may need to modify because im lacking on sleep but, thats what i think it is

gilded void
#

Thanks, i try that.

sacred cradle
#

👍

sick valve
#

hello- im currenlty trying to do code to where when i hit a few keys, the light should change?

#

i cant seem to get it to show up in the game window, and my code isn't showing up w any errors like reference

sacred cradle
#

what are you trying to change with the light? Can you show me your code?

sick valve
#

this is jsut the turning on and off part

#

some other parts of my code work with diff keys, like dooming in and out, and changing the cube's color texture randomly

#

the light parts are giving me trouble

#

some of this code was given by our prof, but the rest was up to us

sacred cradle
#

the script is atatched to a gameobject with the light assigned to the spotlight variable yes?

sick valve
#

yep

#

let me grab it-

sacred cradle
#

thats strange

#

hold on

sick valve
#

what part?

sacred cradle
#

are you getting debug logs when you press q?

sick valve
#

i should say the code also seems to be able to change the color but it never becomes visable-

sick valve
#

it doesnt even wanna turn off after i hit Q again

sacred cradle
#

whats the ! for?

#

i dont know C# amazingly yet

sick valve
#

me neither

north kiln
sacred cradle
#

try this:

if (spotlight.enabled == true)
{
  spotlight.enabled = false;
  Debug.Log("Disabled");
}
else
{
  spotlight.enabled = true;
  Debug.Log("Enabled");
}
sacred cradle
sick valve
#

like this?

sacred cradle
#

yes

naive pawn
sacred cradle
#

mybad

sick valve
#

nothing, only message i get is Enabled

sacred cradle
#

lack of sleep..

naive pawn
sick valve
#

i donto know if the light is working-

sacred cradle
sacred cradle
sick valve
#

well apparently in the logs it did but i still odnt see it

sacred cradle
#

try turn it on in the editor

sick valve
#

i think maybe the directional light might be the only one activated in the scene

naive pawn
sick valve
#

no clue how to swap it

#

enabled?

#

checking it directly how

naive pawn
#

it's a component, right?

sick valve
#

sorry im like. half asleep and its 1 am and i need to get this done b4 10 am

naive pawn
#

the checkbox beside the component name is the enabled state

sick valve
#

oh! yes

naive pawn
#

no, that's for the gameobject

#

that's the active state for the gameobject

#

spotlight is a Light component

sick valve
#

this part?

sacred cradle
#

yeah

naive pawn
#

yes

sacred cradle
#

its enabled

sick valve
#

always was

naive pawn
#

are you sure that's the right object though

naive pawn
# sick valve

it says here that you've assigned an object named Spot Light

#

you showed an object named spotlight

sick valve
#

oh i changed the name to that

#

idk why i thouht it might work then

naive pawn
#

ah, ok.

sick valve
#

still reads in the code

naive pawn
#

hold on, spotlight also has a LevelController?

sick valve
#

i tossed it on there as a last resort

#

if it could read it

naive pawn
#

ok so you have 2 LevelControllers

sick valve
naive pawn
#

one of the LevelControllers toggles it off

#

the other toggles it back on

sick valve
#

shoot-

#

i swear if thats the issue all along-

gilded void
#

But he/she changed the script not?

naive pawn
#

it's still doing the same thing

sick valve
#

okay so i removed the script from the spotlight

naive pawn
#

does it work now?

sick valve
#

i see the words changing, but the light wotn change

#

one sec- i have one feeling

naive pawn
#

do you see the Light getting enabled/disabled?

sick valve
#

yep

#

in the logs

naive pawn
#

in the inspector, i mean

sacred cradle
#

mybad

#

wrong reply

sick valve
#

ill try to get a video, my obs is bugged out so it will be on my phone

sacred cradle
#

ok

naive pawn
sick valve
#

yes

naive pawn
#

yeah i can't make out any detail there

sick valve
#

yeah i see it changing

sick valve
sacred cradle
sick valve
#

yes

sacred cradle
#

can you even see the light in the editor?

sick valve
#

dont think so

sacred cradle
#

probably the issue

naive pawn
#

im not sure enabled has the effect, so just to check:
while in edit mode, go to game view, and try enabling/disabling the light component, see if that makes any difference
if not, try deactivating/reactivating the gameobject, see if that makes any difference

sacred cradle
#

once u get the light to be visible in the editor, try run the game again

naive pawn
sick valve
sacred cradle
sick valve
#

could you please point it out im dumb

sacred cradle
#

all these stuff (mine is different cause i have a different light source)

gilded void
#

And what if you change the gameobject active state and not the light?

naive pawn
sacred cradle
naive pawn
#

no need to apologize, just pointing to places that might be more helpful 🙂

sacred cradle
#

lolll, it was just because they had the wrong settings on there light component. Cant wait for someone to help me with my code 😭

naive pawn
#

@sick valve btw, your old enabled = !enabled was fine, you don't need the if..else on spotlight.enabled

sacred cradle
#

yeah, my janky code is useless

naive pawn
#

it's not janky, it's just the same thing but longer lol

sacred cradle
#

yeah..

naive pawn
#

but i'd recommend the x = !x form, it's clearer in intention

sacred cradle
#

yeah, i just didnt know about that untill now

burnt vapor
#

enabled =^ true; if you like to live dangerously

naive pawn
#

^ works on booleans?

burnt vapor
#

I saw it in an old video, apparently

naive pawn
#

oh, c# also allows |/& on booleans, so i guess not that surprising

#

just not used to it lol

#

......huh.....

burnt vapor
#

Don't ask me why it works

naive pawn
#

ah yeah was wondering why that felt off lmao

#

i know why it works, it just feels like it shouldn't.. initially, at least

naive pawn
#

just ~ that generally doesn't work

sacred cradle
#

no one has helped me 😦

burnt vapor
sacred cradle
#

mybad

topaz mortar
#

Anyone got experience with Vault Inventory package?
Does it work properly? Is it easy to adjust/extend to my own needs?

hexed terrace
cerulean badger
#

guys I'm studying Scriptable Object, but I'm not understanding how I'm supposed to handle multiple objects data, like enemies. For what I'm analysing and testing here, it seems to handle just a single enemy's data per script. If I have 2 or more enemies in the scene, what do I do?

hexed terrace
ornate patio
#

why when I set the transform position of one object to 0,0,0 does it not match the location if I do the same with another object?

cerulean badger
hot laurel
#

its a data container you can store whatever you want, only serialization limits you

hexed terrace
hexed terrace
opaque lichen
#

does on trigger 2d only check if the parented collider is touched or how can I check a different collider from a different game object

wintry quarry
frigid sequoia
#

Ok, so... this pretty much a question about AI navigation, but... pretty sure I am gonna have to mix with some code, so I am gonna ask it here. How could I, make it so entites consider a thing an obstcle, but only if certain conditions are met? And the tricky part, is this is not in an on/off the obstacle, I want the obstacle to be there and considered by everyone as an obstcle, but if I for example tell one particular entity to move INTO the obstacle to ignore it complitely while it is still active for everyone else

drowsy wraith
#

Are you using navmesh?

frigid sequoia
#

Yeah

drowsy wraith
#

You can use navmesh areas and set rules differing for each agent are you familiar with navmesh at all or?

frigid sequoia
#

Not much, but I knew that. Just that they... kinda have to remain as the same type of agent?

drowsy wraith
#

Yeah you can tweak how they interact with navmesh with layers or tags to specifically set which gets considered as an obstacle or not I think code monkey had a video on navmesh id recommend giving it a watch

#

If you still need help tomorrow I’ll help you with it when I’m home

frigid sequoia
#

So the idea is. Blue-ish dude bad guy, he can ignore the obstacles (Red area), Green guys are good guys, they consider the red area an obstacle. I want to the have the liberty of tell some, but not all Green guys to move INTO the red area if want them to, but not ignore ALL red areas (there may be more than one)

drowsy wraith
#

You want to set it or you want it to be randomly assigned ?

frigid sequoia
#

Most areas are supposed to be randomly generated

#

You place waypoints before the areas are placed. I want to make it so some waypoints tell them specifically to move into the area to get into it

#

But also consider not all waypoints affect all Green guys at the same time, they might just affect a bunch

#

I kinda have the feeling that by that point I am gonna kinda just have to tell the object to move towards the waypoint manually and disable the navmesh agent temporally...

exotic jacinth
cosmic dagger
# frigid sequoia So the idea is. Blue-ish dude bad guy, he can ignore the obstacles (Red area), G...

If you want the green guys to move into some of the red areas, you need to place them (red areas) in a collection, and for each green guy, choose a random number based on the collection count to get the total number of red areas they can enter. create a collection on the green guy (using the previous random number as the size), and randomly select from the red area collection until the one on the green guy fills up . . .

frigid sequoia
exotic jacinth
#

https://streamable.com/aumjvq

I’m running into an issue with the zombie animation states. Initially, the zombie wasn’t moving in the Update method, so I used a coroutine to fix that. However, after making this change, the animations are now looping continuously between walking and attacking, even when the zombie should be either walking or attacking based on its distance to the target.

I’m using the remainingDistance and stoppingDistance to transition between walking and attacking, but it seems like the transitions are happening too quickly. The zombie switches between these two states without properly completing either one.

csharp
using System.Collections;
using UnityEngine;
using UnityEngine.AI;

public class ZombieController : MonoBehaviour
{
    public Transform target;
    private Animator animator;
    private NavMeshAgent agent;

    private void Start()
    {
        animator = GetComponent<Animator>();
        agent = GetComponent<NavMeshAgent>();
        

        
        StartCoroutine(UpdateDestinationEvery10Seconds());

    }

    private void Update()
    {
        
        if (agent.remainingDistance > agent.stoppingDistance)
        {
            animator.SetBool("isWalking", true);
            animator.SetBool("isAttacking", false);
        }
        else
        {
            animator.SetBool("isWalking", false);
            animator.SetBool("isAttacking", true);
        }
    }

    private void TrySetDestination()
    {
        
        
            agent.SetDestination(target.transform.position);
        
    }

    
    private IEnumerator UpdateDestinationEvery10Seconds()
    {
        while (true)
        {
            TrySetDestination();
            yield return new WaitForSeconds(1f);  
        }
    }
}

Watch "2025-01-29 19-41-43" on Streamable.

▶ Play video
cosmic dagger
frigid sequoia
#

No, the red areas the Green guys can enter are definetly very specific

#

So.... I place the áreas on a collection, and... I could maybe determine which one they want them to able to enter, now what I do with that?

cosmic dagger
#

Then you should place those areas in a collection to have access to them at any time . . .

cosmic dagger
frigid sequoia
quick edge
#

!code

eternal falconBOT
dark vine
#

guys can anyone help me with this

#

the script doesn't have error i even try test playing it and working fine until i open the script
it said i'm having error on onClick

#

using UnityEngine;
using UnityEngine.UI;
using TMPro;
using System;

public class StatManager : MonoBehaviour
{
public TextMeshProUGUI valueText;
public TextMeshProUGUI modifierText;
public Button increaseButton;
public Button decreaseButton;

public int currentValue = 1;
private int maxValue = 30;
private int minValue = 1;
private int stepValue = 1;

public event Action OnValueChanged;

private void Start()
{
    UpdateValueText();

    increaseButton.onClick.AddListener(IncreaseValue);
    decreaseButton.onClick.AddListener(DecreaseValue);
}

void IncreaseValue()
{
    if (currentValue < maxValue)
    {
        currentValue += stepValue;
        UpdateValueText(); OnValueChanged?.Invoke();
    }
}

void DecreaseValue()
{
    if (currentValue > minValue)
    {
        currentValue -= stepValue;
        UpdateValueText(); OnValueChanged?.Invoke();
    }
}

void UpdateValueText()
{
    valueText.text = currentValue.ToString();
    UpdateModifier();
}

void UpdateModifier()
{
    int modifier = GetModifier(currentValue);
    modifierText.text = modifier >= 0 ? "+" + modifier.ToString() : modifier.ToString();
}

public int GetModifier(int value)
{
    if (value == 1) return -5;
    else if (value <= 3) return -4;
    else if (value <= 5) return -3;
    else if (value <= 7) return -2;
    else if (value <= 9) return -1;
    else if (value <= 11) return +0;
    else if (value <= 13) return 1;
    else if (value <= 15) return 2;
    else if (value <= 17) return 3;
    else if (value <= 19) return 4;
    else if (value <= 21) return 5;
    else if (value <= 23) return 6;
    else if (value <= 25) return 7;
    else if (value <= 27) return 8;
    else if (value <= 29) return 9;
    else if (value <= 30) return 10;
    return 0;
}

}

eternal falconBOT
drowsy wraith
dark vine
# drowsy wraith What’s showing in console ?

'Button' does not contain a definition for 'onClick' and no accessible extension method 'onClick' accepting a first argument of type 'Button' could be found (are you missing a using directive or an assembly reference?)

wintry quarry
dark vine
#

idk man everything was fine i just woke up and open the project and test played it everything was still fine until i open the script and suddenly it got error 💀

wintry quarry
dark vine
#

i haven't even touch the keyboard

covert raft
#

hey guys so just a quick question i wanna make or atleast try to make a game similar to my fav franchise monster hunter any good melee combat vids to get started on

wintry quarry
#

Otherwise the error would be saying UnityEngine.UI.Button does not contain...

cosmic dagger
frigid sequoia
#

Well, the reasons may vary, is just something I want them to be able to do

#

Since the player is supposed to command them in very various ways, so that is something they may want or may want to avoid

#

But the question is, what do I do once I have the obstacle I want them to ignore?

dark vine
wintry quarry
dark vine
#

okay nvm as soon as i checked that
That disappear and now there's no button
Only Button Editor

polar acorn
dark vine
#

sorry 😭

cosmic dagger
frigid sequoia
exotic jacinth
#

https://streamable.com/aumjvq

I’m running into an issue with the zombie animation states. Initially, the zombie wasn’t moving in the Update method, so I used a coroutine to fix that. However, after making this change, the animations are now looping continuously between walking and attacking, even when the zombie should be either walking or attacking based on its distance to the target.

I’m using the remainingDistance and stoppingDistance to transition between walking and attacking, but it seems like the transitions are happening too quickly. The zombie switches between these two states without properly completing either one.

and here's the code below
https://paste.mod.gg/gyoteqsqcdqt/0

Watch "2025-01-29 19-41-43" on Streamable.

▶ Play video
exotic jacinth
cosmic dagger
frigid sequoia
dark vine
#

thanks guys found the error
the " Button " automatically changing to the one in the trash for some reason instead of UnityEngine.UI one

#

sorry for the trouble

drowsy wraith
#

Don’t apologise that’s literally the point of this channel but just send your console when you have an issue

drowsy wraith
verbal dome
#

Or it goes into a blank editor when i try to scroll

drowsy wraith
#

Yeah I’m on mobile haha

#

Yeah it’s scuffed

drowsy wraith
exotic jacinth
#

Okk let me try it

sterile radish
#

hi im trying to reduce the alpha of this sprite everytime i click but it isnt working. heres my code and my error

        spriteRend.color.a -= 64;

"Cannot modify the return value of 'SpriteRenderer.color' because it is not a variable"

naive pawn
#

you have to extract the color out to a variable and reassign it

#
Color color = spriteRend.color;
color.a -= 64;
spriteRend.color = color;
#

though, that 64 is probably wrong

#

color.a is between 0 and 1, not 0 and 255

#

to reduce it by a quarter, you'd have to do -= 0.25f

rocky canyon
swift crag
#

SpriteRenderer.color is a property, so you're actually calling a function when you access it

#

Since it returns Color (a value type), you're trying to modify the copy that the function returns

#

hence the error

#

it is, indeed, not a variable!

#

it's kind of like trying to write 3 = 5

sterile radish
#

ohhh okay i see

rocky canyon
sterile radish
#

its working now, thank you for the help and extra info! ^ ^

swift crag
#

consider...

#
Color color = spriteRend.color;
color.a = Mathf.MoveTowards(color.a, 0, 0.25f);
spriteRend.color = color;
naive pawn
#

255 was treated as 1, so -0.25 should be considered 0 as well

rocky canyon
#

or that ^

cosmic dagger
cosmic dagger
#

This is more of a syntax query. I have a PoolableScriptableObject<T> with a property of type T. Does it make more sense to name the field Item or Value?

var prefab = PoolableScriptableObject<T>.Item;
var prefab = PoolableScriptableObject<T>.Value;
drowsy wraith
# exotic jacinth no it didnt work

No idea man it sounds like it’s between both states so maybe adjust the buffer I can’t see your code for some reason it just won’t load is the attack always playing and they’re just switching between or is attack only playing once ?

brave compass
cosmic dagger
#

T is a C# object. It represents the actual prefab to be pooled. A ScriptableObject is used to store the C# object like a prefab just as you would store a GameObject in the project folder . . .

brave compass
#

Item definition:

an individual article or unit, especially one that is part of a list, collection, or set.

exotic jacinth
# drowsy wraith No idea man it sounds like it’s between both states so maybe adjust the buffer I...
using System.Collections;
using UnityEngine;
using UnityEngine.AI;

public class ZombieController : MonoBehaviour
{
    public Transform target;
    private Animator animator;
    private NavMeshAgent agent;

    private float stateSwitchCooldown = 0.1f;  
    private float lastStateSwitchTime = 0f;  

    private void Start()
    {
        animator = GetComponent<Animator>();
        agent = GetComponent<NavMeshAgent>();
        StartCoroutine(UpdateDestinationEvery10Seconds());
    }

    private void Update()
    {
       
        if (Time.time - lastStateSwitchTime >= stateSwitchCooldown)
        {
            if (agent.remainingDistance > agent.stoppingDistance)
            {
                // Zombie is walking
                animator.SetBool("isWalking", true);
                animator.SetBool("isAttacking", false);
            }
            else
            {
                // Zombie is close to the target and should attack
                animator.SetBool("isWalking", false);
                animator.SetBool("isAttacking", true);
            }

            
            lastStateSwitchTime = Time.time;
        }
    }

    private void TrySetDestination()
    {
        agent.SetDestination(target.transform.position);
    }

    private IEnumerator UpdateDestinationEvery10Seconds()
    {
        while (true)
        {
            TrySetDestination();
            yield return new WaitForSeconds(10f); 
        }
    }
}

heres the code

naive pawn
cosmic dagger
naive pawn
verbal dome
exotic jacinth
verbal dome
#

Oh you said it's a field, so a static field?

cosmic dagger
drowsy wraith
polar acorn
#

Element?

drowsy wraith
#

Just half it and see

inland cobalt
#

Can i still read the linear and angular velocity of a kinematic rigidbody when im moving it with transform? Or do i have to rely on implementing it myself with (currentPos - lastPos) / period;

cosmic dagger
# verbal dome Is this a getter to get an item from the pool?

No, it's a property on a ScriptableObject. I want to pool C# objects. Storing the C# class on a script to use as a prefab works (and exposes it in the editor) but what if I want to re-use that same prefab?

Using a ScriptableObject with a field of the C# class allows me to make prefabs just like dragging a GameObject into the project folder . . .

cosmic dagger
brave compass
#

How do you clone a generic C# object? (question to RandomUnityInvader)

exotic jacinth
verbal dome
drowsy wraith
cosmic dagger
verbal dome
swift crag
#

Prototype would be appropriate.

#

or Template

#

That would make it very obvious that it is the blueprint, rather than a copy

cosmic dagger
brave compass
#

If you're instantiating the scriptable object, Source doesn't make sense to me, because only the original SO will be the source. The duplicated SOs will then also have a field called Source, which doesn't make sense.

swift crag
#

you should avoid using the word "prefab" here, because this is not a prefab

swift crag
verbal dome
#

@brave compass That's true, and if that's the case, you could just directly clone the C# instance without having to clone the whole SO

verbal dome
#

JsonUtility would provide the same functionality as Instantiating the SO

swift crag
#

Ah, so you are instantiating the entire PoolableScriptableObject<Bullet>?

In that case, Value would be a reasonable name

verbal dome
#

We don't know yet!

swift crag
#

I am rather confused here

brave compass
cosmic dagger
# brave compass Still don't understand how you use the serialized value. It's not like you can u...

@swift crag No, I am not Instantiating the SO. ClassObjectPool<T> has a _prefab field which is set to PoolableScriptableObject<T>.Value when the object pool is initialized. To initialize the object pool you must provide an event for public event Func<T,T> Created. E.g., for a bullet object I'd pass in cs private static Bullet CreateBullet(Bullet bullet) => new Bullet(bullet);
The Clone method would invoke the event

    private T Clone()
    {
        Debug.Log($"Creating new object of <color=yellow>{_prefab.Value}</color>.");

        return Created?.Invoke(_prefab.Value);
    }
swift crag
#

Okay, so a few things I'd change

#

PoolableScriptableObject is a misleading name. The scriptable object isn't poolable!

#

It looks like a PoolableScriptableObject<Bullet> is just a way to store a Bullet. Perhaps PooledObjectTemplate<T> would be better?

cosmic dagger
swift crag
#

the asset you're passing in?

cosmic dagger
#

Ignore ObjectPool (up top), that's for actual Unity objects). ClassPool is for C# objects . . .

swift crag
#

You are not instantiating a PoolableBullet. You are cloning some object that's stored in the PoolableBullet unity object

#

Your names should make it clear that this is a container for an object

#

PoolableBullet also implies that this thing is a bullet, and that it's poolable

#

neither of these things are true

cosmic dagger
#

Yes. That's what I'm working on (asking) now. I want better naming conventions for this . . .

swift crag
#

So I'd go with:

PooledObjectTemplate<T> : ScriptableObject // (plus the constraints on T)
BulletTemplate : PooledObjectTemplate<Bullet>
cosmic dagger
#

Item, Value, Source, Element, Template, Container, etc. Generic stuff that represents the object itself and what contains the object . . .

cosmic dagger
swift crag
#

That's reasonable, yeah.

cosmic dagger
swift crag
#

I guess "template" creates a bit of a silly name

#

PoolableObjectTemplate.Template

#

You absoluely can, as long as the abstract class inherits from a Unity object type!

#

But if these are not Unity objects, it gets a bit more complex

#

you can still absolutely store an array or list of an abstract class

#

It just won't be serialized correctly by Unity -- it will only remember the members from the base class

hallow isle
#

Hi all! I'm new to coding in Unity and keep running into a NRE error "Object reference not set to an instance of an object" whenever I try to reference a function from another script. I have the script I'm trying to reference (ScriptB) called in the script I'm working in (ScriptA), and initialized in void Start(). I have looked at a bunch of examples and I'm just not sure what I'm doing wrong. Any help would be super appreciated!

swift crag
polar acorn
#

What line has the error

swift crag
#

(but there are third-party packages to provide the interface)

#

This would be the second use-case -- "You want to use polymorphism..."

hallow isle
swift crag
#

I'm just responding to this last remark here

But it is my understanding that you cannot have an array of an abstract class type.

polar acorn
#

Meaning the find failed

#

You probably shouldn't use find at all, drag in the reference if you can

hallow isle
polar acorn
#

Yes, it's literally dragging the object you want into the box. If the Find fails, you'll be setting the variable to null

#

All of the find methods return null if they can't find the correct thing

swift crag
#

You should use something like FindObjectOfType if and only if you cannot reasonably assign the reference in the inspector.

polar acorn
#

Notably, it doesn't find things that are disabled

swift crag
#

but Object on its own doesn't have the notion of being "active"

#

Perhaps it behaves differently for anything inheriting from Behaviour (and Collider, and Light...?)

polar acorn
#

Ah, right, this is a FindObjectOfType, not a pure Find

swift crag
#

now i'm wondering what that means

hallow isle
#

Thank y'all for that info!!
It's giving the NRE still, is there a specific way that the scripts have to be organized in order to find each other? If one script is inside of another folder in the script folder, is there a way that needs to be specifically referenced in order to find it?

polar acorn
swift crag
#

You can click once on the log entry to be taken to the object that caused the error

hot laurel
#

those properties in point 2 can be applied to every item so basicly you would have one Item class which would implement interfaces for functionality and use scriptable objects to store data of given item, also it can store functionalities, but interfaces cant be serialized, so some worka arounds would be required

verbal dome
#

I don't remember tbh

swift crag
#

you can crash the editor by randomly destroying objects you get from this

#

very funny

verbal dome
thorny basalt
#

I would split the lootable class. One class for the item when it's in your inventory (InventoryItem) and one where it's on the ground (LootItem). The LootItem class can have a inherit from interactable, and have parameter for InventoryItem so that it gives it to the player upon interaction.

drowsy wraith
#

Why would you though ?

#

It’s best to separate them

#

It’s easier to maintain and expand on if they’re separated

#

It’s a good way to handle what you want though for sure

#

Modularity is important for the system you want

thorny basalt
#

Well… Loot item would likely be a game object in the scene, possibly a monobehavoir. An item while in the inventory would be handled by the inventory script. It’s redundant to do both, and will only make it harder to maintain.

hallow isle
#

Is there any way to have a script copy a mesh and create a terrain from the mesh in game? Like if the mesh is changing while in game, the terrain mirrors it

thorny basalt
#

If you need stuff like model data held in the inventory item, you can simply encapsulate it and have LootableItem read it

#

No. I’d just be one way.

#

LootableItem would reference from Inventory item.

cerulean badger
#

I want to make a combat system but I dont have ANY idea of how to do it except for the input. I've attempted to do it but everything was glitching even without console errors so I just deleted it all and I need something or somewhere to give the first steps to this HELL of system (it's 2D btw)

eternal needle
# cerulean badger I want to make a combat system but I dont have ANY idea of how to do it except f...

You need to design and consider what kind of combat you even want. there are tons of tutorials out there, but you'll likely need to add your own logic to customize it for your use case.
part of your message makes it seem like you just need to work on debugging more. "everything was glitching" is not helpful to you at all. You should have a good idea of whats actually going wrong, then for example find out what value is wrong, and why it is wrong

opaque lichen
cosmic dagger
thorny basalt
#

Pass a reference to the player in the interact function

#

Do’d likely need it for other things, like playing an animation when opening doors

last edge
#

hey guys question how do you make an invisible 2d platform? im trying to use my regular platform but changing the Z makes it not interactable

cosmic dagger
last edge
#

because i want like a platform ___ to turn like this



\

cerulean badger
cerulean badger
ashen frigate
polar acorn
#

so if that condition is true multiple times, it'll make more than one

ashen frigate
#

the button is 3d mesh so i use the triggered stay to get get the click virtualmouse to work

polar acorn
#

No I mean it's literally inside a for loop

#

I'm assuming getClicked is only called once so the stay is fine

ashen frigate
#

is there better way to use collision to make it lop ones and let me hover it like the triggeredstay() ?

polar acorn
#

but you're starting a coroutine that contains a loop

eternal needle
#

again not much can be said, especially not without specific examples as to whats not working

ashen frigate
#

yea i thouth maybe the say fuction happend too fast so i tried to slow it down

ashen frigate
#

i only have 1 object that is in 1 eveything else is -1

polar acorn
cerulean badger
ashen frigate
#

ive tried spawning only 1 item not in loop it does the same

ashen frigate
#

Prefab = availablePrefabs[1];
Instantiate(Prefab, Vector3.zero, Quaternion.identity);

cosmic dagger
rocky canyon
polar acorn
eternal needle
cerulean badger
cosmic dagger
cerulean badger
polar acorn
#

Okay, what about the code that doesn't work

cerulean badger
ashen frigate
#

but i dont know any other way

polar acorn
ashen frigate
#

yes